Skip to content

Commit 26e65b0

Browse files
committed
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.
1 parent edd3eaa commit 26e65b0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

+31
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,36 @@ 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+
124+
```js
125+
// this is just a little hack to silence a warning that we'll get until react
126+
// fixes this: https://github.com/facebook/react/pull/14853
127+
const originalError = console.error
128+
beforeAll(() => {
129+
console.error = (...args) => {
130+
if (/Warning.*not wrapped in act/.test(args[0])) {
131+
return
132+
}
133+
originalError.call(console, ...args)
134+
}
135+
})
136+
137+
afterAll(() => {
138+
console.error = originalError
139+
})
140+
```
141+
111142
## Examples
112143

113144
### Basic Example

0 commit comments

Comments
 (0)