enzymejs/enzyme

setState call in cWRP prevents correct cDU call

Open

Aperta il 16 lug 2019

Vedi su GitHub
 (0 commenti) (1 reazione) (0 assegnatari)JavaScript (19.979 star) (2016 fork)batch import
bughelp wantedpackage: react adapter: 16

Descrizione

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

Guida contributor