Skip to content

Commit

Permalink
Test case for reentrant mounting in synchronous mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits committed Dec 22, 2016
1 parent c79af45 commit 884df62
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ src/renderers/shared/shared/__tests__/ReactUpdates-test.js
* throws in setState if the update callback is not a function
* throws in replaceState if the update callback is not a function
* throws in forceUpdate if the update callback is not a function
* handles reentrant mounting in synchronous mode

src/renderers/shared/shared/__tests__/refs-test.js
* Should increase refs with an increase in divs
37 changes: 37 additions & 0 deletions src/renderers/shared/shared/__tests__/ReactUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,4 +1105,41 @@ describe('ReactUpdates', () => {
});
expect(container.textContent).toBe('b');
});

it('handles reentrant mounting in synchronous mode', () => {
var mounts = 0;
class Editor extends React.Component {
render() {
return <div>{this.props.text}</div>;
}
componentDidMount() {
mounts++;
// This should be called only once but we guard just in case.
if (!this.props.rendered) {
this.props.onChange({rendered: true});
}
}
}

var container = document.createElement('div');
function render() {
ReactDOM.render(
<Editor
onChange={(newProps) => {
props = {...props, ...newProps};
render();
}}
{...props}
/>,
container
);
}

var props = {text: 'hello', rendered: false};
render();
props = {...props, text: 'goodbye'};
render();
expect(container.textContent).toBe('goodbye');
expect(mounts).toBe(1);
});
});

0 comments on commit 884df62

Please sign in to comment.