Named snapshots. Tests use act() abstraction.

This commit is contained in:
Brian Vaughn
2019-04-12 08:55:29 -07:00
parent 5d6a2082cc
commit 81183b1492
2 changed files with 75 additions and 51 deletions
+45 -32
View File
@@ -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]
▾ <Grandparent>
▾ <Parent>
<Child key="0">
<Child key="1">
<Child key="2">
<Child key="3">
▾ <Parent>
<Child key="0">
<Child key="1">
<Child key="2">
<Child key="3">
`;
exports[`Store should support mount and update operations 2`] = `
[root]
▾ <Grandparent>
▾ <Parent>
<Child key="0">
<Child key="1">
▾ <Parent>
<Child key="0">
<Child key="1">
`;
exports[`Store should support mount and update operations for multiple roots 1`] = `
[root]
▾ <Parent>
▾ <Parent key="A">
<Child key="0">
<Child key="1">
<Child key="2">
[root]
▾ <Parent>
▾ <Parent key="B">
<Child key="0">
<Child key="1">
`;
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]
▾ <Parent>
▾ <Parent key="A">
<Child key="0">
<Child key="1">
<Child key="2">
<Child key="3">
`;
exports[`Store should support mount and update operations for multiple roots: update 1`] = `
[root]
▾ <Parent key="A">
<Child key="0">
<Child key="1">
<Child key="2">
<Child key="3">
[root]
▾ <Parent>
▾ <Parent key="B">
<Child key="0">
`;
exports[`Store should support mount and update operations: mount 1`] = `
[root]
▾ <Grandparent>
▾ <Parent>
<Child key="0">
<Child key="1">
<Child key="2">
<Child key="3">
▾ <Parent>
<Child key="0">
<Child key="1">
<Child key="2">
<Child key="3">
`;
exports[`Store should support mount and update operations: unmount 1`] = ``;
exports[`Store should support mount and update operations: update 1`] = `
[root]
▾ <Grandparent>
▾ <Parent>
<Child key="0">
<Child key="1">
▾ <Parent>
<Child key="0">
<Child key="1">
`;
+30 -19
View File
@@ -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(<Grandparent count={4} />, container);
act(() => ReactDOM.render(<Grandparent count={4} />, container));
expect(store).toMatchSnapshot('mount');
jest.runAllTimers(); // Flush Bridge operations
act(() => ReactDOM.render(<Grandparent count={2} />, container));
expect(store).toMatchSnapshot('update');
expect(store).toMatchSnapshot();
ReactDOM.render(<Grandparent count={2} />, 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(<Parent count={3} />, containerA);
ReactDOM.render(<Parent count={2} />, containerB);
act(() => {
ReactDOM.render(<Parent key="A" count={3} />, containerA);
ReactDOM.render(<Parent key="B" count={2} />, containerB);
});
expect(store).toMatchSnapshot('mount');
jest.runAllTimers(); // Flush Bridge operations
act(() => {
ReactDOM.render(<Parent key="A" count={4} />, containerA);
ReactDOM.render(<Parent key="B" count={1} />, containerB);
});
expect(store).toMatchSnapshot('update');
expect(store).toMatchSnapshot();
act(() => ReactDOM.unmountComponentAtNode(containerB));
expect(store).toMatchSnapshot('unmount B');
ReactDOM.render(<Parent count={4} />, containerA);
ReactDOM.render(<Parent count={1} />, containerB);
jest.runAllTimers(); // Flush Bridge operations
expect(store).toMatchSnapshot();
act(() => ReactDOM.unmountComponentAtNode(containerA));
expect(store).toMatchSnapshot('unmount A');
});
});