Skip to content

Commit 4d257c0

Browse files
author
James A Rosen
committed
Troubleshooting: add useLayoutEffect + Jest info
1 parent 6c873c7 commit 4d257c0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/troubleshooting.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,30 @@ If you have context issues,
9292
### Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. This usually means that you’re trying to add a ref to a component that doesn’t have an owner
9393

9494
If you’re using React for web, this usually means you have a [duplicate React](https://medium.com/@dan_abramov/two-weird-tricks-that-fix-react-7cf9bbdef375). Follow the linked instructions to fix this.
95+
96+
### I'm getting a warning about useLayoutEffect in my unit tests
97+
98+
ReactDOM emits this warning if `useLayoutEffect` is used "on the server". React Redux tries to get around the issue by detecting whether it is running within a browser context. Jest, by default, defines enough of the browser environment that React Redux thinks it's running in a browser, causing these warnings.
99+
100+
You can prevent the warning by setting the `@jest-environment` for a single test file:
101+
102+
```jsx
103+
// my.test.jsx
104+
/**
105+
* @jest-environment node
106+
*/
107+
```
108+
109+
Or by setting it globally:
110+
111+
```js
112+
// package.json
113+
{
114+
"name": "my-project",
115+
"jest": {
116+
"testEnvironment": "node"
117+
}
118+
}
119+
```
120+
121+
See https://github.com/facebook/react/issues/14927#issuecomment-490426131

0 commit comments

Comments
 (0)