Added separate mount+update tests

This commit is contained in:
Brian Vaughn
2019-04-12 08:55:29 -07:00
parent 74ff8aab45
commit 63e22c645b
2 changed files with 74 additions and 26 deletions
+44 -16
View File
@@ -1,23 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Store should initialize a multiple root tree 1`] = `
[root]
▾ <Parent>
<Child key="one">
<Child key="two">
[root]
▾ <Parent>
<Child key="one">
<Child key="two">
`;
exports[`Store should initialize a simple tree 1`] = `
exports[`Store should support mount and update operations 1`] = `
[root]
▾ <Grandparent>
▾ <Parent>
<Child key="one">
<Child key="two">
<Child key="0">
<Child key="1">
<Child key="2">
<Child key="3">
▾ <Parent>
<Child key="one">
<Child key="two">
<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>
<Child key="0">
<Child key="1">
<Child key="2">
[root]
▾ <Parent>
<Child key="0">
<Child key="1">
`;
exports[`Store should support mount and update operations for multiple roots 2`] = `
[root]
▾ <Parent>
<Child key="0">
<Child key="1">
<Child key="2">
<Child key="3">
[root]
▾ <Parent>
<Child key="0">
`;
+30 -10
View File
@@ -12,29 +12,49 @@ describe('Store', () => {
ReactDOM = require('react-dom');
});
it('should initialize a simple tree', () => {
const Grandparent = () => (
it('should support mount and update operations', () => {
const Grandparent = ({ count }) => (
<React.Fragment>
<Parent />
<Parent />
<Parent count={count} />
<Parent count={count} />
</React.Fragment>
);
const Parent = () => [<Child key="one" />, <Child key="two" />];
const Parent = ({ count }) =>
new Array(count).fill(true).map((_, index) => <Child key={index} />);
const Child = () => <div>Hi!</div>;
ReactDOM.render(<Grandparent />, document.createElement('div'));
const container = document.createElement('div');
ReactDOM.render(<Grandparent count={4} />, container);
jest.runAllTimers(); // Flush Bridge operations
expect(store).toMatchSnapshot();
ReactDOM.render(<Grandparent count={2} />, container);
jest.runAllTimers(); // Flush Bridge operations
expect(store).toMatchSnapshot();
});
it('should initialize a multiple root tree', () => {
const Parent = () => [<Child key="one" />, <Child key="two" />];
it('should support mount and update operations for multiple roots', () => {
const Parent = ({ count }) =>
new Array(count).fill(true).map((_, index) => <Child key={index} />);
const Child = () => <div>Hi!</div>;
ReactDOM.render(<Parent />, document.createElement('div'));
ReactDOM.render(<Parent />, document.createElement('div'));
const containerA = document.createElement('div');
const containerB = document.createElement('div');
ReactDOM.render(<Parent count={3} />, containerA);
ReactDOM.render(<Parent count={2} />, containerB);
jest.runAllTimers(); // Flush Bridge operations
expect(store).toMatchSnapshot();
ReactDOM.render(<Parent count={4} />, containerA);
ReactDOM.render(<Parent count={1} />, containerB);
jest.runAllTimers(); // Flush Bridge operations