-
Notifications
You must be signed in to change notification settings - Fork 10
/
propsInheritance.test.tsx
48 lines (37 loc) · 1.1 KB
/
propsInheritance.test.tsx
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
import React, { Component } from 'react';
import { collect, store as globalStore, WithStoreProp } from '../..';
import * as testUtils from '../testUtils';
type Props = {
visibility: string;
};
const ChildComponent = (props: Props) => (
<div>This component should be {props.visibility}</div>
);
// eslint-disable-next-line react/prefer-stateless-function
class RawClassComponent extends Component<WithStoreProp> {
render() {
const { store } = this.props;
return (
<div>
<button
onClick={() => {
store.clickCount++;
}}
>
Click me
</button>
<ChildComponent
visibility={store.clickCount === 0 ? 'hidden' : 'shown'}
/>
</div>
);
}
}
const ClassComponent = collect(RawClassComponent);
it('should update a child component not wrapped in collect()', () => {
globalStore.clickCount = 0;
const { getByText } = testUtils.renderStrict(<ClassComponent />);
expect(getByText('This component should be hidden'));
getByText('Click me').click();
expect(getByText('This component should be shown'));
});