Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/react-test-renderer/src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <div />;
}
}

const shallowRenderer = createRenderer();
shallowRenderer.render(<SimpleComponent />);
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 (
Expand Down