diff --git a/src/__tests__/__snapshots__/store-test.js.snap b/src/__tests__/__snapshots__/store-test.js.snap index cf044d7e4b..6a8b88da71 100644 --- a/src/__tests__/__snapshots__/store-test.js.snap +++ b/src/__tests__/__snapshots__/store-test.js.snap @@ -1,51 +1,64 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Store should support mount and update operations 1`] = ` +exports[`Store should support mount and update operations for multiple roots: mount 1`] = ` [root] - ▾ - ▾ - - - - - ▾ - - - - -`; - -exports[`Store should support mount and update operations 2`] = ` -[root] - ▾ - ▾ - - - ▾ - - -`; - -exports[`Store should support mount and update operations for multiple roots 1`] = ` -[root] - ▾ + ▾ [root] - ▾ + ▾ `; -exports[`Store should support mount and update operations for multiple roots 2`] = ` +exports[`Store should support mount and update operations for multiple roots: unmount A 1`] = ``; + +exports[`Store should support mount and update operations for multiple roots: unmount B 1`] = ` [root] - ▾ + ▾ + + + + +`; + +exports[`Store should support mount and update operations for multiple roots: update 1`] = ` +[root] + ▾ [root] - ▾ + ▾ `; + +exports[`Store should support mount and update operations: mount 1`] = ` +[root] + ▾ + ▾ + + + + + ▾ + + + + +`; + +exports[`Store should support mount and update operations: unmount 1`] = ``; + +exports[`Store should support mount and update operations: update 1`] = ` +[root] + ▾ + ▾ + + + ▾ + + +`; diff --git a/src/__tests__/store-test.js b/src/__tests__/store-test.js index fb779cf4fc..6d21a5bbd5 100644 --- a/src/__tests__/store-test.js +++ b/src/__tests__/store-test.js @@ -3,13 +3,23 @@ describe('Store', () => { let React; let ReactDOM; + let TestUtils; let store; + const act = (callback: Function) => { + TestUtils.act(() => { + callback(); + }); + + jest.runAllTimers(); // Flush Bridge operations + }; + beforeEach(() => { store = global.store; React = require('react'); ReactDOM = require('react-dom'); + TestUtils = require('react-dom/test-utils'); }); it('should support mount and update operations', () => { @@ -25,17 +35,14 @@ describe('Store', () => { const container = document.createElement('div'); - ReactDOM.render(, container); + act(() => ReactDOM.render(, container)); + expect(store).toMatchSnapshot('mount'); - jest.runAllTimers(); // Flush Bridge operations + act(() => ReactDOM.render(, container)); + expect(store).toMatchSnapshot('update'); - expect(store).toMatchSnapshot(); - - ReactDOM.render(, container); - - jest.runAllTimers(); // Flush Bridge operations - - expect(store).toMatchSnapshot(); + act(() => ReactDOM.unmountComponentAtNode(container)); + expect(store).toMatchSnapshot('unmount'); }); it('should support mount and update operations for multiple roots', () => { @@ -46,18 +53,22 @@ describe('Store', () => { const containerA = document.createElement('div'); const containerB = document.createElement('div'); - ReactDOM.render(, containerA); - ReactDOM.render(, containerB); + act(() => { + ReactDOM.render(, containerA); + ReactDOM.render(, containerB); + }); + expect(store).toMatchSnapshot('mount'); - jest.runAllTimers(); // Flush Bridge operations + act(() => { + ReactDOM.render(, containerA); + ReactDOM.render(, containerB); + }); + expect(store).toMatchSnapshot('update'); - expect(store).toMatchSnapshot(); + act(() => ReactDOM.unmountComponentAtNode(containerB)); + expect(store).toMatchSnapshot('unmount B'); - ReactDOM.render(, containerA); - ReactDOM.render(, containerB); - - jest.runAllTimers(); // Flush Bridge operations - - expect(store).toMatchSnapshot(); + act(() => ReactDOM.unmountComponentAtNode(containerA)); + expect(store).toMatchSnapshot('unmount A'); }); });