Hey guys,
our tests stopped working since yesterday, apparently after the new 2.4.0 release.
It seems like the lifecycle hook shouldComponentUpdate is not triggered when updating props. Here is an example to reproduce it.
const customRenderMixin = {
shouldComponentUpdate () {
console.log('should update')
return false
},
}
const TestComponent = React.createClass({
mixins: [customRenderMixin],
propTypes: {
onUpdate: PropTypes.func.isRequired,
},
componentWillReceiveProps () {
console.log('receiving props')
},
componentWillUpdate (...args) {
console.log('receiving update')
this.props.onUpdate(...args)
},
render () {
return null
},
})
test('component should not update with no change', t => {
const onUpdateSpy = spy()
const props = { onUpdate: onUpdateSpy }
const wrapper = shallow(<TestComponent {...props} />)
wrapper.setProps(props)
t.equal(onUpdateSpy.called, false, 'component should not re-render')
t.end()
})
With version 2.3.0
component should not update with no change
receiving props
should update
✔ component should not re-render
With version 2.4.0
component should not update with no change
receiving props
receiving update
✖ component should not re-render
---------------------------------
operator: equal
expected: false
actual: true
Failed Tests: There was 1 failure
component should not update with no change
✖ component should not re-render
Thanks for the report @emmenko, I believe https://github.com/airbnb/enzyme/pull/491 should fix your issue.
@Aweary oh awesome, I missed it :) Many thanks!! 👍
Published 2.4.1 which should have the fix!
@lelandrichardson ahah, that was quick! Awesome support, thanks guys! 😉
Most helpful comment
Published 2.4.1 which should have the fix!