Skip to content
Merged
Changes from all commits
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
21 changes: 20 additions & 1 deletion docs/react-testing-library/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ If you want to make things more like shallow rendering, then you could do
something more [like this](example-react-transition-group.md).

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed this and couldn't help myself 🙃


</details>

Expand Down Expand Up @@ -178,6 +178,25 @@ 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 one of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to make sure people knew that any of the async utilities will solve this. And in many cases using a find* query makes a lot of sense, so I changed the example to that.

[the async utilities](/docs/dom-testing-library/api-async) like
[wait](/docs/dom-testing-library/api-async#wait) or a
[`find*` query](/docs/dom-testing-library/api-queries#findby). For example:
`const userAddress = await findByLabel(/address/i)`.
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