Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/act-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ function withGlobalActEnvironment(actImplementation) {
return actResult
}
} catch (error) {
// https://github.com/testing-library/react-testing-library/issues/1392
// https://github.com/testing-library/react-testing-library/issues/1399
if (
// Error.isError is pretty new addition to Node.js - may not be available in LTS versions
Error.isError &&
Error.isError(error) &&
error.toString() === 'TypeError: React.act is not a function' &&
process &&
process.env.NODE_ENV === 'production'
) {
throw new Error(
'Following error may be caused by `NODE_ENV` environment variable being set to `production`. Try changing it to `test`.',
{cause: error},
)
}
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
// or if we have to await the callback first.
setIsReactActEnvironment(previousActEnvironment)
Expand Down
Loading