Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shallow test renderer calls shouldComponentUpdate on forceUpdate #11236

Closed
d4rky-pl opened this issue Oct 16, 2017 · 2 comments
Closed

Shallow test renderer calls shouldComponentUpdate on forceUpdate #11236

d4rky-pl opened this issue Oct 16, 2017 · 2 comments

Comments

@d4rky-pl
Copy link
Contributor

d4rky-pl commented Oct 16, 2017

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
  })
})
@gaearon gaearon changed the title shallow test renderer calls shouldComponentUpdate on forceUpdate Shallow test renderer calls shouldComponentUpdate on forceUpdate Oct 17, 2017
@gaearon
Copy link
Collaborator

gaearon commented Nov 3, 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.

@d4rky-pl
Copy link
Contributor Author

d4rky-pl commented Nov 3, 2017

@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.

Apologies for extra noise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants