Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add FAQ about "update not wrapped in act" warnings
This has comes up every so often in issues and Spectrum, so I've tried to summarize the cause & resolutions available.
  • Loading branch information
grncdr authored Sep 10, 2019
commit add09581826f21b95aae283d3a6eb64beca2e754
16 changes: 16 additions & 0 deletions docs/react-testing-library/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ snapshotDiff(firstVersion, container.cloneNode(true))

</details>

<details>

<summary>How do I fix "an update was not wrapped in act(...)" warnings?</summary>

This warning is usually caused by an async operation causing an update after
the test has already finished. There are 2 approaches to resolve it:

1. Wait for the result of the operation in your test by using [wait](https://testing-library.com/docs/dom-testing-library/api-async#wait). For example: `await wait(() => getByText("fetch completed")`.
[an example in this issue](https://github.com/testing-library/react-testing-library/issues/441#issuecomment-520977388).
2. Mocking out the asynchronous operation so that it doesn't trigger state updates.

Generally speaking, approach 1 is preferred since it better matches the expectations
of a user interacting with your app.

</details>

<!--
Links:
-->
Expand Down