|
@@ -1,5 +1,5 @@
|
1
|
|
-require('react-native');
|
2
|
1
|
import React from 'react';
|
|
2
|
+require('react-native');
|
3
|
3
|
import renderer from 'react-test-renderer';
|
4
|
4
|
|
5
|
5
|
describe('remx support', () => {
|
|
@@ -7,40 +7,43 @@ describe('remx support', () => {
|
7
|
7
|
let store;
|
8
|
8
|
|
9
|
9
|
beforeEach(() => {
|
|
10
|
+ jest.resetModules();
|
10
|
11
|
MyConnectedContainer = require('./component').default;
|
11
|
12
|
store = require('./store');
|
12
|
13
|
});
|
13
|
14
|
|
14
|
15
|
it('renders normally', () => {
|
15
|
|
- const tree = renderer.create(<MyConnectedContainer/>);
|
|
16
|
+ const tree = renderer.create(<MyConnectedContainer />);
|
16
|
17
|
expect(tree.toJSON().children).toEqual(['no name']);
|
17
|
18
|
});
|
18
|
19
|
|
19
|
20
|
it('rerenders as a result of an underlying state change (by selector)', () => {
|
20
|
|
- const tree = renderer.create(<MyConnectedContainer/>);
|
|
21
|
+ const renderCountIncrement = jest.fn();
|
|
22
|
+ const tree = renderer.create(<MyConnectedContainer renderCountIncrement={renderCountIncrement} />);
|
21
|
23
|
const instance = tree.getInstance();
|
22
|
24
|
|
23
|
25
|
expect(tree.toJSON().children).toEqual(['no name']);
|
24
|
|
- expect(instance.renders).toEqual(1);
|
|
26
|
+ expect(renderCountIncrement).toHaveBeenCalledTimes(1);
|
25
|
27
|
|
26
|
|
- store.mutators.setName('Bob');
|
27
|
|
- expect(store.selectors.getName()).toEqual('Bob');
|
|
28
|
+ store.setters.setName('Bob');
|
|
29
|
+ expect(store.getters.getName()).toEqual('Bob');
|
28
|
30
|
expect(tree.toJSON().children).toEqual(['Bob']);
|
29
|
31
|
|
30
|
|
- expect(instance.renders).toEqual(2);
|
|
32
|
+ expect(renderCountIncrement).toHaveBeenCalledTimes(2);
|
31
|
33
|
});
|
32
|
34
|
|
33
|
35
|
it('rerenders as a result of an underlying state change with a new key using merge', () => {
|
34
|
|
- const tree = renderer.create(<MyConnectedContainer printAge={true}/>);
|
|
36
|
+ const renderCountIncrement = jest.fn();
|
|
37
|
+ const tree = renderer.create(<MyConnectedContainer printAge={true} renderCountIncrement={renderCountIncrement} />);
|
35
|
38
|
const instance = tree.getInstance();
|
36
|
39
|
|
37
|
40
|
expect(tree.toJSON().children).toEqual(null);
|
38
|
|
- expect(instance.renders).toEqual(1);
|
|
41
|
+ expect(renderCountIncrement).toHaveBeenCalledTimes(1);
|
39
|
42
|
|
40
|
|
- store.mutators.setAge(30);
|
41
|
|
- expect(store.selectors.getAge()).toEqual(30);
|
|
43
|
+ store.setters.setAge(30);
|
|
44
|
+ expect(store.getters.getAge()).toEqual(30);
|
42
|
45
|
expect(tree.toJSON().children).toEqual([30]);
|
43
|
46
|
|
44
|
|
- expect(instance.renders).toEqual(2);
|
|
47
|
+ expect(renderCountIncrement).toHaveBeenCalledTimes(2);
|
45
|
48
|
});
|
46
|
49
|
});
|