Skip to content

Commit 54d060b

Browse files
JSFernandesKent C. Dodds
and
Kent C. Dodds
committed
docs: Document known issue with React 16.8 (#423)
* docs: Document known issue with React 16.8 These warnings will be common among users with React 16.8. By adding this to the README we can address a common concern until React 16.9 becomes common. * Update README.md Co-authored-by: Kent C. Dodds <[email protected]>
1 parent edd3eaa commit 54d060b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: README.md

+32
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ practices.</p>
5656
- [The problem](#the-problem)
5757
- [This solution](#this-solution)
5858
- [Installation](#installation)
59+
- [Suppressing unnecessary warnings on React DOM 16.8](#suppressing-unnecessary-warnings-on-react-dom-168)
5960
- [Examples](#examples)
6061
- [Basic Example](#basic-example)
6162
- [Complex Example](#complex-example)
@@ -108,6 +109,37 @@ use [the custom jest matchers](https://github.com/testing-library/jest-dom).
108109

109110
> [**Docs**](https://testing-library.com/react)
110111
112+
### Suppressing unnecessary warnings on React DOM 16.8
113+
114+
There is a known compatibility issue with React DOM 16.8 where you will see the
115+
following warning:
116+
117+
```
118+
Warning: An update to ComponentName inside a test was not wrapped in act(...).
119+
```
120+
121+
If you cannot upgrade to React DOM 16.9, you may suppress the warnings by adding
122+
the following snippet to your test configuration
123+
([learn more](https://github.com/testing-library/react-testing-library/issues/281)):
124+
125+
```js
126+
// this is just a little hack to silence a warning that we'll get until we
127+
// upgrade to 16.9: https://github.com/facebook/react/pull/14853
128+
const originalError = console.error
129+
beforeAll(() => {
130+
console.error = (...args) => {
131+
if (/Warning.*not wrapped in act/.test(args[0])) {
132+
return
133+
}
134+
originalError.call(console, ...args)
135+
}
136+
})
137+
138+
afterAll(() => {
139+
console.error = originalError
140+
})
141+
```
142+
111143
## Examples
112144

113145
### Basic Example

0 commit comments

Comments
 (0)