(mode: any, props?: Partial<SelectProps>)
| 5 | import { render } from '@testing-library/react'; |
| 6 | |
| 7 | export default function dynamicChildrenTest(mode: any, props?: Partial<SelectProps>) { |
| 8 | injectRunAllTimers(jest); |
| 9 | |
| 10 | beforeEach(() => { |
| 11 | jest.useFakeTimers(); |
| 12 | }); |
| 13 | |
| 14 | afterEach(() => { |
| 15 | jest.useRealTimers(); |
| 16 | }); |
| 17 | |
| 18 | it('dynamic children', () => { |
| 19 | const onChange = jest.fn(); |
| 20 | const onSelect = jest.fn(); |
| 21 | |
| 22 | class App extends React.Component { |
| 23 | public state = { |
| 24 | value: ['1'], |
| 25 | options: [ |
| 26 | <Option key="1" testprop="test"> |
| 27 | 1-label |
| 28 | </Option>, |
| 29 | <Option key="2">2-label</Option>, |
| 30 | ], |
| 31 | }; |
| 32 | |
| 33 | public select: any; |
| 34 | |
| 35 | public componentDidMount() { |
| 36 | setTimeout(() => { |
| 37 | this.updateChildren(); |
| 38 | }, 10); |
| 39 | } |
| 40 | |
| 41 | public updateChildren = () => { |
| 42 | this.setState({ |
| 43 | options: [<Option key="2">2-label</Option>, <Option key="3">3-label</Option>], |
| 44 | }); |
| 45 | }; |
| 46 | |
| 47 | public render() { |
| 48 | return ( |
| 49 | <Select |
| 50 | value={this.state.value} |
| 51 | ref={(node) => { |
| 52 | this.select = node; |
| 53 | }} |
| 54 | mode={mode} |
| 55 | {...props} |
| 56 | onChange={onChange} |
| 57 | onSelect={onSelect} |
| 58 | > |
| 59 | {this.state.options} |
| 60 | </Select> |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 |
no test coverage detected
searching dependent graphs…