|
6 | 6 | react/no-render-return-value: "warn"
|
7 | 7 | */
|
8 | 8 | import TestUtils from 'react-addons-test-utils';
|
9 |
| -import React from 'react'; |
| 9 | +import React, { Component } from 'react'; |
10 | 10 | import sinon from 'sinon';
|
11 | 11 | import expect from 'expect';
|
12 | 12 | import ReactDOM from 'react-dom';
|
@@ -519,4 +519,37 @@ describe('Modal', () => {
|
519 | 519 | done();
|
520 | 520 | }, closeTimeoutMS);
|
521 | 521 | });
|
| 522 | + |
| 523 | + it('shouldn\'t throw if forcibly unmounted during mounting', () => { |
| 524 | + /* eslint-disable camelcase, react/prop-types */ |
| 525 | + class Wrapper extends Component { |
| 526 | + constructor (props) { |
| 527 | + super(props); |
| 528 | + this.state = { error: false }; |
| 529 | + } |
| 530 | + unstable_handleError () { |
| 531 | + this.setState({ error: true }); |
| 532 | + } |
| 533 | + render () { |
| 534 | + return this.state.error ? null : <div>{ this.props.children }</div>; |
| 535 | + } |
| 536 | + } |
| 537 | + /* eslint-enable camelcase, react/prop-types */ |
| 538 | + |
| 539 | + const Throw = () => { throw new Error('reason'); }; |
| 540 | + const TestCase = () => ( |
| 541 | + <Wrapper> |
| 542 | + <Modal /> |
| 543 | + <Throw /> |
| 544 | + </Wrapper> |
| 545 | + ); |
| 546 | + |
| 547 | + const currentDiv = document.createElement('div'); |
| 548 | + document.body.appendChild(currentDiv); |
| 549 | + |
| 550 | + const mount = () => ReactDOM.render(<TestCase />, currentDiv); |
| 551 | + expect(mount).toNotThrow(); |
| 552 | + |
| 553 | + document.body.removeChild(currentDiv); |
| 554 | + }); |
522 | 555 | });
|
0 commit comments