-
Notifications
You must be signed in to change notification settings - Fork 49k
Closed
Description
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.
This for example breaks shallow rendering in Enzyme when using MobX and observables.
Minimal test case:
import React from 'react'
import ShallowRenderer from 'react-test-renderer/shallow';
const renderer = new ShallowRenderer();
class TestComponent extends React.Component {
render() { return <span/> }
}
describe('forceUpdate', () => {
it('does not call shouldComponentUpdate', () => {
let called = 0
TestComponent.prototype.shouldComponentUpdate = () => called += 1
const component = renderer.render(<TestComponent/>);
renderer._instance.forceUpdate()
expect(called).toBe(0) // <- this throws because called === 1
})
})