Enzyme: Lifecycle broken (shouldComponentUpdate) from 2.3.0 to 2.4.0

Created on 8 Jul 2016  ·  4Comments  ·  Source: enzymejs/enzyme

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
shallow bug

Most helpful comment

Published 2.4.1 which should have the fix!

All 4 comments

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! 😉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewhl picture andrewhl  ·  3Comments

AdamYahid picture AdamYahid  ·  3Comments

nelsonchen90 picture nelsonchen90  ·  3Comments

blainekasten picture blainekasten  ·  3Comments

ivanbtrujillo picture ivanbtrujillo  ·  3Comments