Skip to content

Commit

Permalink
Add test logic to make sure that events get tested when rendering on …
Browse files Browse the repository at this point in the history
…top of server-generated markup. (facebook#6668)
  • Loading branch information
aickin authored and jimfb committed Apr 30, 2016
1 parent 4f01b4b commit 256753b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/renderers/dom/server/__tests__/ReactServerRendering-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,26 +232,32 @@ describe('ReactServerRendering', function() {
ExecutionEnvironment.canUseDOM = true;
element.innerHTML = lastMarkup;

ReactDOM.render(<TestComponent name="x" />, element);
var instance = ReactDOM.render(<TestComponent name="x" />, element);
expect(mountCount).toEqual(3);
expect(element.innerHTML).toBe(lastMarkup);

// Ensure the events system works after mount into server markup
expect(numClicks).toEqual(0);
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(instance.refs.span));
expect(numClicks).toEqual(1);

ReactDOM.unmountComponentAtNode(element);
expect(element.innerHTML).toEqual('');

// Now simulate a situation where the app is not idempotent. React should
// warn but do the right thing.
element.innerHTML = lastMarkup;
spyOn(console, 'error');
var instance = ReactDOM.render(<TestComponent name="y" />, element);
instance = ReactDOM.render(<TestComponent name="y" />, element);
expect(mountCount).toEqual(4);
expect(console.error.argsForCall.length).toBe(1);
expect(element.innerHTML.length > 0).toBe(true);
expect(element.innerHTML).not.toEqual(lastMarkup);

// Ensure the events system works
expect(numClicks).toEqual(0);
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(instance.refs.span));
// Ensure the events system works after markup mismatch.
expect(numClicks).toEqual(1);
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(instance.refs.span));
expect(numClicks).toEqual(2);
});

it('should throw with silly args', function() {
Expand Down

0 comments on commit 256753b

Please sign in to comment.