enzymejs/enzyme

setState call in cWRP prevents correct cDU call

Open

#2191 opened on Jul 16, 2019

View on GitHub
 (0 comments) (1 reaction) (0 assignees)JavaScript (19,979 stars) (2,016 forks)batch import
bughelp wantedpackage: react adapter: 16

Description

Current behavior

I have a project at work where calling shallowWrapper.setProps({...}) doesn't trigger componentDidUpdate() if the preceding componentWillReceiveProps() invokes setState({...}).

I was unable to replicate this in Enzyme's unit tests, but I observed a slightly different bug there: If componentWillReceiveProps() calls setState(), the subsequent componentDidUpdate() receives the same set of props as both this.props and nextProps. Test case

In both cases, I observe the failure only with the React 16 adapter. With the React 15 adapter, I see the expected behavior.

Expected behavior

Calling setState() in componentWillReceiveProps() should have no effect on whether componentDidUpdate() is called or what it sees as this.props.

Your environment

API

  • shallow

Version

library version
enzyme 3.10.0
react 16.8.5
react-dom 16.8.5
react-test-renderer 16.8.6
adapter (below) 1.12.1

Adapter

  • enzyme-adapter-react-16

Contributor guide