-
-
Notifications
You must be signed in to change notification settings - Fork 2k
enzyme@3: wrapper is not updated even if there was a new render #1153
Copy link
Copy link
Closed
Description
Hi. Just faced this after updating to v3.
Given the following deps:
├─ enzyme-adapter-react-16@1.0.0
├─ enzyme@3.0.0
├─ react-dom@16.0.0
├─ react-test-renderer@16.0.0
└─ react@16.0.0
And the HOC:
import React, { Component } from 'react'
const testHOC = (Target) => class TestClass extends Component {
constructor (...args) {
super(...args)
this.state = {}
this.onTest = this.onTest.bind(this)
}
onTest () {
this.setState({
foo: true
})
}
render () {
console.log(this.state)
return (
<Target {...this.props} {...this.state} onTest={this.onTest} />
)
}
}
export default testHOCAnd the test:
import React from 'react'
import { mount } from 'enzyme'
import testHOC from './testHOC'
describe('testHOC', () => {
it('should work', () => {
const Target = () => null
const EnhancedTarget = testHOC(Target)
const wrapper = mount(
<EnhancedTarget />
)
wrapper.find(Target).prop('onTest')()
console.log(
wrapper.debug()
)
})
})I see:
console.log testHOC.js:18
{ foo: true }
console.log testHOC.spec.js:15
<TestClass>
<Target onTest={[Function]} />
</TestClass>
So the was a new render, but wrapper just didn't react to it. Works fine with v2.
Please correct me if I was wrong all this time and test should be written in another way.
Reactions are currently unavailable