Enzyme: componentDidUpdate is not called when a component calls setState()

Created on 16 Aug 2018  路  4Comments  路  Source: enzymejs/enzyme

When a component uses setState() the componentDidUpdate call is supposed to fire and any code within it is supposed to be executed. Enzyme 3.4.1 does not execute the cDU code when setState() is called within the component.

To Reproduce
Steps to reproduce the behavior:

  1. Make sure enzyme 3.4.1 is installed: npm install [email protected]
  2. Create a component that takes a callback prop, contains the componentDidUpdate method and another method that calls setState(). The cDU method should execute the callback when it's fired.
  3. Create a test which spies on the callback prop and executes the component method which calls setState()
  4. Notice that the cDU is not executed

Expected behavior
cDU should be executed when a component's setState is called.

Desktop (please complete the following information):

  • OS: iOS
  • Browser Node
  • Version 8.11.3

Additional context
https://github.com/airbnb/enzyme/issues/1452
https://github.com/airbnb/enzyme/pull/1742#issuecomment-413341308

Code Sample

https://github.com/ajbogh/enzyme-setstate-bug

Most helpful comment

v3.4.2 fixed the issue! Thanks for the great work.

All 4 comments

@ajbogh https://github.com/airbnb/enzyme/pull/1742 isn't included v3.4.1 so please wait for the next release!

Oh. Thanks @koba04. My mistake. I'll check back when the release happens.

v3.4.2 is released; I'll reopen this if the issue isn't addressed.

v3.4.2 fixed the issue! Thanks for the great work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewhl picture andrewhl  路  3Comments

aweary picture aweary  路  3Comments

amcmillan01 picture amcmillan01  路  3Comments

dschinkel picture dschinkel  路  3Comments

timhonders picture timhonders  路  3Comments