diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index 956005da561ad..fc3baf251f029 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -147,9 +147,11 @@ class ReactShallowRenderer { // Fallback to previous instance state to support rendering React.cloneElement() const state = this._newState || this._instance.state || emptyObject; - if (typeof this._instance.shouldComponentUpdate === 'function') { + if ( + typeof this._instance.shouldComponentUpdate === 'function' && + !this._forcedUpdate + ) { if ( - this._forcedUpdate || this._instance.shouldComponentUpdate(props, state, context) === false ) { this._instance.context = context; diff --git a/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js b/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js index 55647fbaaf342..1f51e390040b6 100644 --- a/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js +++ b/packages/react-test-renderer/src/__tests__/ReactShallowRenderer-test.js @@ -142,6 +142,24 @@ describe('ReactShallowRenderer', () => { expect(scuCounter).toEqual(0); }); + it('should rerender when calling forceUpdate', () => { + let renderCounter = 0; + class SimpleComponent extends React.Component { + render() { + renderCounter += 1; + return
; + } + } + + const shallowRenderer = createRenderer(); + shallowRenderer.render(); + expect(renderCounter).toEqual(1); + + const instance = shallowRenderer.getMountedInstance(); + instance.forceUpdate(); + expect(renderCounter).toEqual(2); + }); + it('should shallow render a functional component', () => { function SomeComponent(props, context) { return (