forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremx.test.js
54 lines (41 loc) · 1.92 KB
/
remx.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const React = require('react');
require('react-native');
const renderer = require('react-test-renderer');
const { Navigation } = require('../../lib/dist/index');
describe('remx support', () => {
let MyConnectedComponent;
let store;
beforeEach(() => {
MyConnectedComponent = require('./MyComponent');
store = require('./MyStore');
});
it('renders normally', () => {
const tree = renderer.create(<MyConnectedComponent />);
expect(tree.toJSON().children).toEqual(['no name']);
});
it('rerenders as a result of an underlying state change (by selector)', () => {
const renderCountIncrement = jest.fn();
const tree = renderer.create(<MyConnectedComponent renderCountIncrement={renderCountIncrement} />);
expect(tree.toJSON().children).toEqual(['no name']);
expect(renderCountIncrement).toHaveBeenCalledTimes(1);
store.setters.setName('Bob');
expect(store.getters.getName()).toEqual('Bob');
expect(tree.toJSON().children).toEqual(['Bob']);
expect(renderCountIncrement).toHaveBeenCalledTimes(2);
});
it('rerenders as a result of an underlying state change with a new key', () => {
const renderCountIncrement = jest.fn();
const tree = renderer.create(<MyConnectedComponent printAge={true} renderCountIncrement={renderCountIncrement} />);
expect(tree.toJSON().children).toEqual(null);
expect(renderCountIncrement).toHaveBeenCalledTimes(1);
store.setters.setAge(30);
expect(store.getters.getAge()).toEqual(30);
expect(tree.toJSON().children).toEqual(['30']);
expect(renderCountIncrement).toHaveBeenCalledTimes(2);
});
it('support for static members in connected components', () => {
expect(MyConnectedComponent.options).toEqual({ title: 'MyComponent' });
const registeredComponentClass = Navigation.registerComponent('MyComponentName', () => MyConnectedComponent)();
expect(registeredComponentClass.options).toEqual({ title: 'MyComponent' });
});
});