|
@@ -61,21 +61,21 @@ describe('ComponentWrapper', () => {
|
61
|
61
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
62
|
62
|
expect(NavigationComponent).not.toBeInstanceOf(MyComponent);
|
63
|
63
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
64
|
|
- expect(tree.toJSON().children).toEqual(['Hello, World!']);
|
65
|
|
- expect(tree.getInstance().originalComponentRef).toBeInstanceOf(MyComponent);
|
|
64
|
+ expect(tree.toJSON()!.children).toEqual(['Hello, World!']);
|
|
65
|
+ expect(tree.getInstance()!.originalComponentRef).toBeInstanceOf(MyComponent);
|
66
|
66
|
});
|
67
|
67
|
|
68
|
68
|
it('injects props from wrapper into original component', () => {
|
69
|
69
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
70
|
70
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} myProp={'yo'} />);
|
71
|
|
- expect(tree.getInstance().originalComponentRef.props.myProp).toEqual('yo');
|
|
71
|
+ expect(tree.getInstance()!.originalComponentRef.props.myProp).toEqual('yo');
|
72
|
72
|
});
|
73
|
73
|
|
74
|
74
|
it('updates props from wrapper into original component', () => {
|
75
|
75
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
76
|
76
|
const tree = renderer.create(<TestParent ChildClass={NavigationComponent} />);
|
77
|
77
|
expect(childRef.props.foo).toEqual(undefined);
|
78
|
|
- tree.getInstance().setState({ propsFromState: { foo: 'yo' } });
|
|
78
|
+ tree.getInstance()!.setState({ propsFromState: { foo: 'yo' } });
|
79
|
79
|
expect(childRef.props.foo).toEqual('yo');
|
80
|
80
|
});
|
81
|
81
|
|
|
@@ -83,7 +83,7 @@ describe('ComponentWrapper', () => {
|
83
|
83
|
store.setPropsForComponentId('component123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
84
|
84
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
85
|
85
|
const tree = renderer.create(<NavigationComponent componentId={'component123'} />);
|
86
|
|
- const originalComponentProps = tree.getInstance().originalComponentRef.props;
|
|
86
|
+ const originalComponentProps = tree.getInstance()!.originalComponentRef.props;
|
87
|
87
|
expect(originalComponentProps).toEqual({ componentId: 'component123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
|
88
|
88
|
});
|
89
|
89
|
|
|
@@ -93,7 +93,7 @@ describe('ComponentWrapper', () => {
|
93
|
93
|
store.setPropsForComponentId('component1', { myProp: 'hello' });
|
94
|
94
|
expect(childRef.originalComponentRef.props.foo).toEqual(undefined);
|
95
|
95
|
expect(childRef.originalComponentRef.props.myProp).toEqual(undefined);
|
96
|
|
- tree.getInstance().setState({ propsFromState: { foo: 'yo' } });
|
|
96
|
+ tree.getInstance()!.setState({ propsFromState: { foo: 'yo' } });
|
97
|
97
|
expect(childRef.originalComponentRef.props.foo).toEqual('yo');
|
98
|
98
|
expect(childRef.originalComponentRef.props.myProp).toEqual('hello');
|
99
|
99
|
});
|
|
@@ -102,15 +102,15 @@ describe('ComponentWrapper', () => {
|
102
|
102
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
103
|
103
|
const tree = renderer.create(<TestParent ChildClass={NavigationComponent} />);
|
104
|
104
|
expect(childRef.originalComponentRef.props.componentId).toEqual('component1');
|
105
|
|
- tree.getInstance().setState({ propsFromState: { id: 'ERROR' } });
|
|
105
|
+ tree.getInstance()!.setState({ propsFromState: { id: 'ERROR' } });
|
106
|
106
|
expect(childRef.originalComponentRef.props.componentId).toEqual('component1');
|
107
|
107
|
});
|
108
|
108
|
|
109
|
109
|
it('assignes key by id', () => {
|
110
|
110
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
111
|
111
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
112
|
|
- expect(tree.getInstance().originalComponentRef.props.componentId).toEqual('component1');
|
113
|
|
- expect(tree.getInstance().originalComponentRef._reactInternalInstance.key).toEqual('component1');
|
|
112
|
+ expect(tree.getInstance()!.originalComponentRef.props.componentId).toEqual('component1');
|
|
113
|
+ expect(tree.getInstance()!.originalComponentRef._reactInternalInstance.key).toEqual('component1');
|
114
|
114
|
});
|
115
|
115
|
|
116
|
116
|
it('saves self ref into store', () => {
|
|
@@ -131,14 +131,14 @@ describe('ComponentWrapper', () => {
|
131
|
131
|
it('holds ref to OriginalComponent', () => {
|
132
|
132
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
133
|
133
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
134
|
|
- expect(tree.getInstance().originalComponentRef).toBeDefined();
|
135
|
|
- expect(tree.getInstance().originalComponentRef).toBeInstanceOf(MyComponent);
|
|
134
|
+ expect(tree.getInstance()!.originalComponentRef).toBeDefined();
|
|
135
|
+ expect(tree.getInstance()!.originalComponentRef).toBeInstanceOf(MyComponent);
|
136
|
136
|
});
|
137
|
137
|
|
138
|
138
|
it('cleans ref to internal component on unount', () => {
|
139
|
139
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
140
|
140
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
141
|
|
- const instance = tree.getInstance();
|
|
141
|
+ const instance = tree.getInstance()!;
|
142
|
142
|
expect(instance.originalComponentRef).toBeInstanceOf(React.Component);
|
143
|
143
|
tree.unmount();
|
144
|
144
|
expect(instance.originalComponentRef).toBeFalsy();
|
|
@@ -166,16 +166,16 @@ describe('ComponentWrapper', () => {
|
166
|
166
|
it('didAppear, didDisappear and onNavigationButtonPressed are optional', () => {
|
167
|
167
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyComponent, store);
|
168
|
168
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
169
|
|
- expect(() => tree.getInstance().didAppear()).not.toThrow();
|
170
|
|
- expect(() => tree.getInstance().didDisappear()).not.toThrow();
|
171
|
|
- expect(() => tree.getInstance().onNavigationButtonPressed()).not.toThrow();
|
|
169
|
+ expect(() => tree.getInstance()!.didAppear()).not.toThrow();
|
|
170
|
+ expect(() => tree.getInstance()!.didDisappear()).not.toThrow();
|
|
171
|
+ expect(() => tree.getInstance()!.onNavigationButtonPressed()).not.toThrow();
|
172
|
172
|
});
|
173
|
173
|
|
174
|
174
|
it('calls didAppear on OriginalComponent', () => {
|
175
|
175
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
|
176
|
176
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
177
|
177
|
expect(didAppearCallback).toHaveBeenCalledTimes(0);
|
178
|
|
- tree.getInstance().didAppear();
|
|
178
|
+ tree.getInstance()!.didAppear();
|
179
|
179
|
expect(didAppearCallback).toHaveBeenCalledTimes(1);
|
180
|
180
|
});
|
181
|
181
|
|
|
@@ -183,7 +183,7 @@ describe('ComponentWrapper', () => {
|
183
|
183
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
|
184
|
184
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
185
|
185
|
expect(didDisappearCallback).toHaveBeenCalledTimes(0);
|
186
|
|
- tree.getInstance().didDisappear();
|
|
186
|
+ tree.getInstance()!.didDisappear();
|
187
|
187
|
expect(didDisappearCallback).toHaveBeenCalledTimes(1);
|
188
|
188
|
});
|
189
|
189
|
|
|
@@ -191,7 +191,7 @@ describe('ComponentWrapper', () => {
|
191
|
191
|
const NavigationComponent = ComponentWrapper.wrap(componentName, MyLifecycleComponent, store);
|
192
|
192
|
const tree = renderer.create(<NavigationComponent componentId={'component1'} />);
|
193
|
193
|
expect(onNavigationButtonPressedCallback).toHaveBeenCalledTimes(0);
|
194
|
|
- tree.getInstance().onNavigationButtonPressed();
|
|
194
|
+ tree.getInstance()!.onNavigationButtonPressed();
|
195
|
195
|
expect(onNavigationButtonPressedCallback).toHaveBeenCalledTimes(1);
|
196
|
196
|
});
|
197
|
197
|
});
|