diff --git a/packages/component-test-utils-react/src/shallow.js b/packages/component-test-utils-react/src/shallow.js index 12773ff..a0ca86f 100644 --- a/packages/component-test-utils-react/src/shallow.js +++ b/packages/component-test-utils-react/src/shallow.js @@ -25,7 +25,7 @@ class ShallowRender { this._render(); } - _render(customProps) { + _render(customProps, forceUpdate) { let firstRender = false; const prevDispatcher = ReactCurrentDispatcher.current; @@ -65,6 +65,7 @@ class ShallowRender { this._instance.props = props; if ( + !forceUpdate && !firstRender && typeof this._instance.shouldComponentUpdate === 'function' && !this._instance.shouldComponentUpdate( diff --git a/packages/component-test-utils-react/src/shallow.spec.js b/packages/component-test-utils-react/src/shallow.spec.js index f56b10b..290020b 100644 --- a/packages/component-test-utils-react/src/shallow.spec.js +++ b/packages/component-test-utils-react/src/shallow.spec.js @@ -1036,7 +1036,28 @@ describe('react shallow render', () => { describe('componentDidCatch', () => { // TODO }); - describe('forceUpdate', () => {}); + describe('forceUpdate', () => { + it('should trigger a render whenever shouldComponentUpdate return false', () => { + class Component extends React.Component { + shouldComponentUpdate() { + return false; + } + + render() { + return ( +
this.forceUpdate()}>{this.props.value}
+ ); + } + } + + const cmp = shallow(); + + cmp.setProps({value: 42}); + cmp.dispatchEvent('Click'); + + expect(cmp.html()).toEqual('
42
'); + }); + }); describe('displayName', () => { it('should ovewrite the name displayed by html method', () => { diff --git a/packages/component-test-utils-react/src/updater/updater.js b/packages/component-test-utils-react/src/updater/updater.js index 2b622c1..95876a9 100644 --- a/packages/component-test-utils-react/src/updater/updater.js +++ b/packages/component-test-utils-react/src/updater/updater.js @@ -28,7 +28,7 @@ export class Updater { enqueueForceUpdate(publicInstance, callback) { this._enqueueCallback(callback, publicInstance); - this._shallow._render(); + this._shallow._render(undefined, true); } enqueueReplaceState(publicInstance, completeState, callback) {