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

Avoid confusing behaviour caused by deferred hook execution #33

Closed
robertknight opened this issue Apr 14, 2019 · 2 comments
Closed

Avoid confusing behaviour caused by deferred hook execution #33

robertknight opened this issue Apr 14, 2019 · 2 comments

Comments

@robertknight
Copy link
Member

robertknight commented Apr 14, 2019

After-paint actions scheduled with useEffect are currently scheduled to execute using requestAnimationFrame followed by a setTimeout(callback, 0) by default. It isn't very obvious how to:

  • Make any pending effects execute and update the Enzyme wrapper to reflect the final rendered state
  • Clean up properly at the end of a test

From what I gather, this is the not-very-clearly explained purpose of act() (React docs).

I think what we'll want to do here is:

  1. Wrap the initial render in act() so that all effects have executed by the time the developer starts interacting with the returned wrapper
  2. Wrapper event dispatches and other updates through the wrapper in act for the same reason
  3. Make sure there is documentation in place about what to do for manipulations of components that happen outside of the wrapper (timeouts, events manually dispatched to DOM elements etc.)
  4. Try to figure out how to simplify cleanup at the end of a test

I also wonder whether the adapter should automatically register a replacement for options.requestAnimationFrame, since we want tests to execute as fast as possible.

@robertknight
Copy link
Member Author

robertknight commented Apr 14, 2019

Another thing we could do would be to make the {MountRenderer, ShallowRenderer}#getNode methods flush any pending effects and renders before returning the node. This would at least provide a predictable way (wrapper.update()) of ensuring that everything was up to date before querying the wrapper. I need to check if this is consistent with how the React adapters work.

@robertknight
Copy link
Member Author

#34 resolved the problem for the initial case that prompted me to open this issue.

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

No branches or pull requests

1 participant