@samitouri / QOS-React-2 / commits / 1bdae952b5

Added separate mount+update tests

Brian Vaughn committed Apr 11, 2019 at 09:27 UTC 1bdae952b5e5675d5124d5d968522e8acc85065f
2 files changed +71 -23
src/__tests__/__snapshots__/store-test.js.snap
+41 -13
@@ -1,23 +1,51 @@
1 // Jest Snapshot v1, https://goo.gl/fbAQLP
2
3 -exports[`Store should initialize a multiple root tree 1`] = `
3 +exports[`Store should support mount and update operations 1`] = `
4 [root]
5 - ▾ <Parent>
6 - <Child key="one">
7 - <Child key="two">
8 -[root]
9 - ▾ <Parent>
10 - <Child key="one">
11 - <Child key="two">
5 + ▾ <Grandparent>
6 + ▾ <Parent>
7 + <Child key="0">
8 + <Child key="1">
9 + <Child key="2">
10 + <Child key="3">
11 + ▾ <Parent>
12 + <Child key="0">
13 + <Child key="1">
14 + <Child key="2">
15 + <Child key="3">
16 `;
17
14 -exports[`Store should initialize a simple tree 1`] = `
18 +exports[`Store should support mount and update operations 2`] = `
19 [root]
20 ▾ <Grandparent>
21 ▾ <Parent>
18 - <Child key="one">
19 - <Child key="two">
22 + <Child key="0">
23 + <Child key="1">
24 ▾ <Parent>
21 - <Child key="one">
22 - <Child key="two">
25 + <Child key="0">
26 + <Child key="1">
27 +`;
28 +
29 +exports[`Store should support mount and update operations for multiple roots 1`] = `
30 +[root]
31 + ▾ <Parent>
32 + <Child key="0">
33 + <Child key="1">
34 + <Child key="2">
35 +[root]
36 + ▾ <Parent>
37 + <Child key="0">
38 + <Child key="1">
39 +`;
40 +
41 +exports[`Store should support mount and update operations for multiple roots 2`] = `
42 +[root]
43 + ▾ <Parent>
44 + <Child key="0">
45 + <Child key="1">
46 + <Child key="2">
47 + <Child key="3">
48 +[root]
49 + ▾ <Parent>
50 + <Child key="0">
51 `;
src/__tests__/store-test.js
+30 -10
@@ -12,29 +12,49 @@ describe('Store', () => {
12 ReactDOM = require('react-dom');
13 });
14
15 - it('should initialize a simple tree', () => {
16 - const Grandparent = () => (
15 + it('should support mount and update operations', () => {
16 + const Grandparent = ({ count }) => (
17 <React.Fragment>
18 - <Parent />
19 - <Parent />
18 + <Parent count={count} />
19 + <Parent count={count} />
20 </React.Fragment>
21 );
22 - const Parent = () => [<Child key="one" />, <Child key="two" />];
22 + const Parent = ({ count }) =>
23 + new Array(count).fill(true).map((_, index) => <Child key={index} />);
24 const Child = () => <div>Hi!</div>;
25
25 - ReactDOM.render(<Grandparent />, document.createElement('div'));
26 + const container = document.createElement('div');
27 +
28 + ReactDOM.render(<Grandparent count={4} />, container);
29 +
30 + jest.runAllTimers(); // Flush Bridge operations
31 +
32 + expect(store).toMatchSnapshot();
33 +
34 + ReactDOM.render(<Grandparent count={2} />, container);
35
36 jest.runAllTimers(); // Flush Bridge operations
37
38 expect(store).toMatchSnapshot();
39 });
40
32 - it('should initialize a multiple root tree', () => {
33 - const Parent = () => [<Child key="one" />, <Child key="two" />];
41 + it('should support mount and update operations for multiple roots', () => {
42 + const Parent = ({ count }) =>
43 + new Array(count).fill(true).map((_, index) => <Child key={index} />);
44 const Child = () => <div>Hi!</div>;
45
36 - ReactDOM.render(<Parent />, document.createElement('div'));
37 - ReactDOM.render(<Parent />, document.createElement('div'));
46 + const containerA = document.createElement('div');
47 + const containerB = document.createElement('div');
48 +
49 + ReactDOM.render(<Parent count={3} />, containerA);
50 + ReactDOM.render(<Parent count={2} />, containerB);
51 +
52 + jest.runAllTimers(); // Flush Bridge operations
53 +
54 + expect(store).toMatchSnapshot();
55 +
56 + ReactDOM.render(<Parent count={4} />, containerA);
57 + ReactDOM.render(<Parent count={1} />, containerB);
58
59 jest.runAllTimers(); // Flush Bridge operations
60