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

Add test to repro problem with mocking out 'getDerivedStateFromProps' #6000

Closed

Commits on Apr 16, 2018

  1. Add test to repro problem with mocking out 'getDerivedStateFromProps'

    **what is the change?:**
    Soon folks will be adopting the new 'getDerivedStateFromProps' in their
    React components, and re-running existing tests.
    
    If those components are mocked in existing tests, then React will throw
    errors currently.
    
    Why? Because React validates that any component defining this method has
    state and returns the right thing from 'gDSFP', and when an auto-mock is
    created it doesn't fit these invariants.
    
    Talking through this with @mael and @mjesun we determined an easy
    solution is to add a small conditional to either blacklist mocking
    functions with this name, so that automocks just don't have this method
    and the invariant is never checked in React.
    
    An alternative solution would be to make the mocked 'gDSFP' method
    return 'null' and define 'state' on the mocked component.
    
    **why make this change?:**
    Let's work together to make Jest and React work together incredibly
    smoothly, like a sea of butter. ^_^
    
    **test plan:**
    This test will throw errors right now - tagging @mjesun to tweak Jest so
    that the new test will pass correctly.
    
    (Flarnie will insert screenshot of the errors thrown)
    flarnie committed Apr 16, 2018
    Configuration menu
    Copy the full SHA
    7d7fbc8 View commit details
    Browse the repository at this point in the history
  2. Fix linting

    Miguel Jimenez Esun committed Apr 16, 2018
    Configuration menu
    Copy the full SHA
    ac26a1a View commit details
    Browse the repository at this point in the history