Skip to content

Commit 535b757

Browse files
grncdrKent C. Dodds
andcommitted
Add FAQ about "update not wrapped in act" warnings (testing-library#255)
* 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. * Update faq.md * Update faq.md Co-authored-by: Kent C. Dodds <[email protected]>
1 parent ceeb514 commit 535b757

File tree

1 file changed

+20
-1
lines changed
  • docs/react-testing-library

1 file changed

+20
-1
lines changed

docs/react-testing-library/faq.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ If you want to make things more like shallow rendering, then you could do
126126
something more [like this](example-react-transition-group.md).
127127

128128
Learn more about how Jest mocks work from my blog post:
129-
["But really, what is a JavaScript mock?"](https://blog.kentcdodds.com/but-really-what-is-a-javascript-mock-10d060966f7d)
129+
["But really, what is a JavaScript mock?"](https://kentcdodds.com/blog/but-really-what-is-a-javascript-mock)
130130

131131
</details>
132132

@@ -178,6 +178,25 @@ snapshotDiff(firstVersion, container.cloneNode(true))
178178

179179
</details>
180180

181+
<details>
182+
183+
<summary>How do I fix "an update was not wrapped in act(...)" warnings?</summary>
184+
185+
This warning is usually caused by an async operation causing an update after
186+
the test has already finished. There are 2 approaches to resolve it:
187+
188+
1. Wait for the result of the operation in your test by using one of
189+
[the async utilities](/docs/dom-testing-library/api-async) like
190+
[wait](/docs/dom-testing-library/api-async#wait) or a
191+
[`find*` query](/docs/dom-testing-library/api-queries#findby). For example:
192+
`const userAddress = await findByLabel(/address/i)`.
193+
2. Mocking out the asynchronous operation so that it doesn't trigger state updates.
194+
195+
Generally speaking, approach 1 is preferred since it better matches the expectations
196+
of a user interacting with your app.
197+
198+
</details>
199+
181200
<!--
182201
Links:
183202
-->

0 commit comments

Comments
 (0)