forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStore.test.ts
62 lines (49 loc) · 2.06 KB
/
Store.test.ts
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
55
56
57
58
59
60
61
62
import * as React from 'react';
import { Store } from './Store';
import { IWrappedComponent } from './ComponentWrapper';
describe('Store', () => {
let uut: Store;
beforeEach(() => {
uut = new Store();
});
it('initial state', () => {
expect(uut.getPropsForId('component1')).toEqual({});
});
it('holds props by id', () => {
uut.setPropsForId('component1', { a: 1, b: 2 });
expect(uut.getPropsForId('component1')).toEqual({ a: 1, b: 2 });
});
it('defensive for invalid Id and props', () => {
uut.setPropsForId('component1', undefined);
expect(uut.getPropsForId('component1')).toEqual({});
});
it('holds original components classes by componentName', () => {
const MyWrappedComponent = () => class MyComponent extends React.Component {};
uut.setComponentClassForName('example.mycomponent', MyWrappedComponent);
expect(uut.getComponentClassForName('example.mycomponent')).toEqual(MyWrappedComponent);
});
it('clear props by component id when clear component', () => {
uut.setPropsForId('refUniqueId', { foo: 'bar' });
uut.clearComponent('refUniqueId');
expect(uut.getPropsForId('refUniqueId')).toEqual({});
});
it('clear instance by component id when clear component', () => {
uut.setComponentInstance('refUniqueId', ({} as IWrappedComponent));
uut.clearComponent('refUniqueId');
expect(uut.getComponentInstance('refUniqueId')).toEqual(undefined);
});
it('holds component instance by id', () => {
uut.setComponentInstance('component1', ({} as IWrappedComponent));
expect(uut.getComponentInstance('component1')).toEqual({});
});
it('calls component setProps when set props by id', () => {
const instance: any = {setProps: jest.fn()};
const props = { foo: 'bar' };
uut.setComponentInstance('component1', instance);
uut.setPropsForId('component1', props);
expect(instance.setProps).toHaveBeenCalledWith(props);
});
it('not throw exeption when set props by id component not found', () => {
expect(() => uut.setPropsForId('component1', { foo: 'bar' })).not.toThrow();
});
});