setTimeout needed with enzyme 3.10.0
- Dominant language
- JavaScript
- Stars
- 19.8k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
### Current behavior
I have component including following:
```
componentDidMount() {
this.props.errors.observe('errorShow', this.errorShowHandler)
this.props.errors.observe('errorHide', this.errorHideHandler)
}
errorShowHandler(errorObject) {
this.setState({errorMessage: errorObject.code})
}
errorHideHandler() {
this.setState({errorMessage: undefined})
}
render() {
if (this.state.errorMessage) {
return (
)
}
return null
}
```
And following way to test this:
```
describe('when error appears', () => {
let wrapper, errors
beforeAll(() => {
errors = new ObservableModel()
const strings = {}
wrapper = mount()
errors.update('errorShow', { code: 'TEST_ERROR' } )
wrapper.update()
})
it('should show error code', () => {
expect(wrapper.text()).toContain('TEST_ERROR')
})
describe('when error is hidden', () => {
beforeAll(() => {
errors.update('errorHide')
wrapper.update()
})
it('should not show error message', () => {
expect(wrapper.find('#error').length).toBe(0)
})
})
```
### Expected behavior
Second test should work also with enzyme 3.10.0 but instead it says that "Expected 1 to be 0." Same test works with enzyme 3.7.0 - 3.9.0. Modifying test like this makes it also work with 3.10.0:
```
it('should not show error message', () => {
setTimeout(function() { expect(wrapper.find('#error').length).toBe(0) }, 500)
})
```
### Your environment
#### API
- [ ] shallow
- [x] mount
- [ ] render
#### Version
| library | version
| ------------------- | -------
| enzyme | 3.10.0
| react | 16.11.0
| react-dom | 16.11.0
| react-test-renderer | 16.11.0
| adapter (below) | 1.6.0
#### Adapter
- [x] enzyme-adapter-react-16
- [ ] enzyme-adapter-react-16.3
- [ ] enzyme-adapter-react-16.2
- [ ] enzyme-adapter-react-16.1
- [ ] enzyme-adapter-react-15
- [ ] enzyme-adapter-react-15.4
- [ ] enzyme-adapter-react-14
- [ ] enzyme-adapter-react-13
- [ ] enzyme-adapter-react-helper
- [ ] others ( )
Contributor guide
Research direction
Reproduce the mount case with Enzyme 3.10.0, React 16.11.0, and enzyme-adapter-react-16 1.6.0, then compare it with Enzyme 3.9.0. Investigate the update behavior after errors.update('errorHide') and confirm that the error element is removed synchronously without setTimeout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100