You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Bug What is the current behavior?
In react-test-renderer/shallow, the shallow renderer will set instance state in getDerviedStateFromProps so the this.state and nextState will be the same in shouldComponentUpdate, which is different with the behavior of real rendering.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
render with ReactDOM, the shouldComponentUpdate will return true since this.state will be the old value initial:
constdivRef=React.createRef()constdiv=document.createElement('div')// in real test code we have to add a `ref={divRef}` in the `div` of SimpleComponentconstinitialResult=ReactDOM.render(<SimpleComponentvalue="initial"/>,div);expect(divRef.current.classList[0]).toEqual("initial");// will output `shouldUpdate: true`constupdatedResult=ReactDOM.render(<SimpleComponentvalue="updated"/>,div);// so the class name changesexpect(divRef.current.classList[0]).toEqual("updated");
In shallow renderer, the behavior is different:
constshallowRenderer=createRenderer();constinitialResult=shallowRenderer.render(<SimpleComponentvalue="initial"/>);expect(initialResult).toEqual(<div>value:initial</div>);// will not update, since in `shouldComponentUpdate` the `this.state` has been updated// after `getDeriveStateFromProps` and as same as passed `nextState`constupdatedResult=shallowRenderer.render(<SimpleComponentvalue="updated"/>);// the following assert will failexpect(updatedResult).toEqual(<div>value:updated</div>);
What is the expected behavior?
ShallowRenderer should not set the instance state in getDeriveStateFromProps, or in the shouldComponentUpdate we have no way to compare it.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
I have tested this in master branch and 16.3, both not work.
By the way this problem is related to enzymejs/enzyme#1970 . If it's recoginzed as a bug I can provide a PR in next several days.
The text was updated successfully, but these errors were encountered:
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
In
react-test-renderer/shallow
, the shallow renderer will set instance state ingetDerviedStateFromProps
so thethis.state
andnextState
will be the same inshouldComponentUpdate
, which is different with the behavior of real rendering.If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
given below class component:
render with ReactDOM, the
shouldComponentUpdate
will return true sincethis.state
will be the old valueinitial
:In shallow renderer, the behavior is different:
What is the expected behavior?
ShallowRenderer should not set the instance state in getDeriveStateFromProps, or in the
shouldComponentUpdate
we have no way to compare it.Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
I have tested this in master branch and 16.3, both not work.
By the way this problem is related to enzymejs/enzyme#1970 . If it's recoginzed as a bug I can provide a PR in next several days.
The text was updated successfully, but these errors were encountered: