|
1 | 1 | /* eslint-env mocha */
|
2 | 2 | import sinon from 'sinon';
|
3 | 3 | import expect from 'expect';
|
4 |
| -import React from 'react'; |
| 4 | +import React, { Component } from 'react'; |
5 | 5 | import ReactDOM from 'react-dom';
|
6 | 6 | import TestUtils from 'react-addons-test-utils';
|
7 | 7 | import Modal from '../lib/components/Modal';
|
@@ -308,4 +308,37 @@ describe('State', () => {
|
308 | 308 | done();
|
309 | 309 | }, closeTimeoutMS);
|
310 | 310 | });
|
| 311 | + |
| 312 | + it('shouldn\'t throw if forcibly unmounted during mounting', () => { |
| 313 | + /* eslint-disable camelcase, react/prop-types */ |
| 314 | + class Wrapper extends Component { |
| 315 | + constructor (props) { |
| 316 | + super(props); |
| 317 | + this.state = { error: false }; |
| 318 | + } |
| 319 | + unstable_handleError () { |
| 320 | + this.setState({ error: true }); |
| 321 | + } |
| 322 | + render () { |
| 323 | + return this.state.error ? null : <div>{ this.props.children }</div>; |
| 324 | + } |
| 325 | + } |
| 326 | + /* eslint-enable camelcase, react/prop-types */ |
| 327 | + |
| 328 | + const Throw = () => { throw new Error('reason'); }; |
| 329 | + const TestCase = () => ( |
| 330 | + <Wrapper> |
| 331 | + <Modal /> |
| 332 | + <Throw /> |
| 333 | + </Wrapper> |
| 334 | + ); |
| 335 | + |
| 336 | + const currentDiv = document.createElement('div'); |
| 337 | + document.body.appendChild(currentDiv); |
| 338 | + |
| 339 | + const mount = () => ReactDOM.render(<TestCase />, currentDiv); |
| 340 | + expect(mount).toNotThrow(); |
| 341 | + |
| 342 | + document.body.removeChild(currentDiv); |
| 343 | + }); |
311 | 344 | });
|
0 commit comments