From 256753b83011f18dab8f6f12535afc78c5652b69 Mon Sep 17 00:00:00 2001 From: Sasha Aickin Date: Sat, 30 Apr 2016 11:21:34 -0700 Subject: [PATCH] Add test logic to make sure that events get tested when rendering on top of server-generated markup. (#6668) --- .../__tests__/ReactServerRendering-test.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/renderers/dom/server/__tests__/ReactServerRendering-test.js b/src/renderers/dom/server/__tests__/ReactServerRendering-test.js index c679e03793e22..d3919e7b93bec 100644 --- a/src/renderers/dom/server/__tests__/ReactServerRendering-test.js +++ b/src/renderers/dom/server/__tests__/ReactServerRendering-test.js @@ -232,9 +232,15 @@ describe('ReactServerRendering', function() { ExecutionEnvironment.canUseDOM = true; element.innerHTML = lastMarkup; - ReactDOM.render(, element); + var instance = ReactDOM.render(, 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(''); @@ -242,16 +248,16 @@ describe('ReactServerRendering', function() { // warn but do the right thing. element.innerHTML = lastMarkup; spyOn(console, 'error'); - var instance = ReactDOM.render(, element); + instance = ReactDOM.render(, 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() {