|
@@ -53,7 +53,7 @@ describe('ComponentWrapper', () => {
|
53
|
53
|
});
|
54
|
54
|
|
55
|
55
|
it('must have componentId as prop', () => {
|
56
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
56
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
57
|
57
|
const orig = console.error;
|
58
|
58
|
console.error = (a) => a;
|
59
|
59
|
expect(() => {
|
|
@@ -63,7 +63,7 @@ describe('ComponentWrapper', () => {
|
63
|
63
|
});
|
64
|
64
|
|
65
|
65
|
it('wraps the component', () => {
|
66
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
66
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
67
|
67
|
expect(NavigationComponent).not.toBeInstanceOf(MyComponent);
|
68
|
68
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
69
|
69
|
expect(tree.toJSON()!.children).toEqual(['Hello, World!']);
|
|
@@ -71,14 +71,14 @@ describe('ComponentWrapper', () => {
|
71
|
71
|
|
72
|
72
|
it('injects props from wrapper into original component', () => {
|
73
|
73
|
const renderCount = jest.fn();
|
74
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
74
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
75
|
75
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} text={'yo'} renderCount={renderCount} />);
|
76
|
76
|
expect(tree.toJSON()!.children).toEqual(['yo']);
|
77
|
77
|
expect(renderCount).toHaveBeenCalledTimes(1);
|
78
|
78
|
});
|
79
|
79
|
|
80
|
80
|
it('updates props from wrapper into original component on state change', () => {
|
81
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
81
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
82
|
82
|
const tree = renderer.create(<TestParent ChildClass={NavigationComponent} />);
|
83
|
83
|
expect(myComponentProps.foo).toEqual(undefined);
|
84
|
84
|
(tree.getInstance() as any).setState({ propsFromState: { foo: 'yo' } });
|
|
@@ -87,13 +87,13 @@ describe('ComponentWrapper', () => {
|
87
|
87
|
|
88
|
88
|
it('pulls props from the store and injects them into the inner component', () => {
|
89
|
89
|
store.setPropsForId('component123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
90
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
90
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
91
|
91
|
renderer.create(<NavigationComponent componentId={'component123'} />);
|
92
|
92
|
expect(myComponentProps).toEqual({ componentId: 'component123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
93
|
93
|
});
|
94
|
94
|
|
95
|
95
|
it('updates props from store into inner component', () => {
|
96
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
96
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
97
|
97
|
const tree = renderer.create(<TestParent ChildClass={NavigationComponent} />);
|
98
|
98
|
store.setPropsForId('component1', { myProp: 'hello' });
|
99
|
99
|
expect(myComponentProps.foo).toEqual(undefined);
|
|
@@ -104,7 +104,7 @@ describe('ComponentWrapper', () => {
|
104
|
104
|
});
|
105
|
105
|
|
106
|
106
|
it('protects id from change', () => {
|
107
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
107
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
108
|
108
|
const tree = renderer.create(<TestParent ChildClass={NavigationComponent} />);
|
109
|
109
|
expect(myComponentProps.componentId).toEqual('component1');
|
110
|
110
|
(tree.getInstance() as any).setState({ propsFromState: { id: 'ERROR' } });
|
|
@@ -112,7 +112,7 @@ describe('ComponentWrapper', () => {
|
112
|
112
|
});
|
113
|
113
|
|
114
|
114
|
it('assignes key by id', () => {
|
115
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
115
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
116
|
116
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
117
|
117
|
expect(myComponentProps.componentId).toEqual('component1');
|
118
|
118
|
expect((tree.getInstance() as any)._reactInternalInstance.child.key).toEqual('component1');
|
|
@@ -120,20 +120,20 @@ describe('ComponentWrapper', () => {
|
120
|
120
|
|
121
|
121
|
it('cleans props from store on unMount', () => {
|
122
|
122
|
store.setPropsForId('component123', { foo: 'bar' });
|
123
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
123
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
124
|
124
|
const tree = renderer.create(<NavigationComponent componentId={'component123'} />);
|
125
|
125
|
expect(store.getPropsForId('component123')).toEqual({ foo: 'bar' });
|
126
|
126
|
tree.unmount();
|
127
|
127
|
expect(store.getPropsForId('component123')).toEqual({});
|
128
|
128
|
});
|
129
|
129
|
|
130
|
|
- it(`merges static members from wrapped component`, () => {
|
131
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver) as any;
|
|
130
|
+ it(`merges static members from wrapped component when generated`, () => {
|
|
131
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver) as any;
|
132
|
132
|
expect(NavigationComponent.options).toEqual({ title: 'MyComponentTitle' });
|
133
|
133
|
});
|
134
|
134
|
|
135
|
135
|
it(`calls unmounted on componentEventsObserver`, () => {
|
136
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store, componentEventsObserver);
|
|
136
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => MyComponent, store, componentEventsObserver);
|
137
|
137
|
const tree = renderer.create(<NavigationComponent componentId={'component123'} />);
|
138
|
138
|
verify(mockedComponentEventsObserver.unmounted('component123')).never();
|
139
|
139
|
tree.unmount();
|
|
@@ -162,7 +162,7 @@ describe('ComponentWrapper', () => {
|
162
|
162
|
const reduxStore = require('redux').createStore((state = initialState) => state);
|
163
|
163
|
|
164
|
164
|
it(`wraps the component with a react-redux provider with passed store`, () => {
|
165
|
|
- const NavigationComponent = ComponentWrapper.wrap(componentName, ConnectedComp, store, componentEventsObserver, ReduxProvider, reduxStore);
|
|
165
|
+ const NavigationComponent = ComponentWrapper.wrap(componentName, () => ConnectedComp, store, componentEventsObserver, ReduxProvider, reduxStore);
|
166
|
166
|
const tree = renderer.create(<NavigationComponent componentId={'theCompId'} />);
|
167
|
167
|
expect(tree.toJSON()!.children).toEqual(['it just works']);
|
168
|
168
|
expect((NavigationComponent as any).options).toEqual({ foo: 123 });
|