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
There is no extra guard or clause in enqueueForceUpdate when calling render which means the render always calls shouldComponentUpdate which can block even forced re-render during tests.
importReactfrom'react'importShallowRendererfrom'react-test-renderer/shallow';constrenderer=newShallowRenderer();classTestComponentextendsReact.Component{render(){return<span/>}}describe('forceUpdate',()=>{it('does not call shouldComponentUpdate',()=>{letcalled=0TestComponent.prototype.shouldComponentUpdate=()=>called+=1constcomponent=renderer.render(<TestComponent/>);renderer._instance.forceUpdate()expect(called).toBe(0)// <- this throws because called === 1})})
The text was updated successfully, but these errors were encountered:
gaearon
changed the title
shallow test renderer calls shouldComponentUpdate on forceUpdate
Shallow test renderer calls shouldComponentUpdate on forceUpdate
Oct 17, 2017
React 16.1.0-beta has been released. Please update react, react-dom, and react-test-renderer (if you use it) to this version and let us know if it solved the issue! We’d appreciate if you could test before Monday when we plan to get 16.1.0 out.
@gaearon Hey, it seems that I actually botched this fix - the shouldComponentUpdate() is no longer called but the component is still not rerendered properly (check was done in wrong if clause). I've sent another PR that resolves this, please check #11439.
There is no extra guard or clause in
enqueueForceUpdate
when callingrender
which means therender
always callsshouldComponentUpdate
which can block even forced re-render during tests.This for example breaks shallow rendering in Enzyme when using MobX and observables.
Minimal test case:
The text was updated successfully, but these errors were encountered: