diff --git a/src/act-compat.js b/src/act-compat.js index 6eaec0fb..2b4d1168 100644 --- a/src/act-compat.js +++ b/src/act-compat.js @@ -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)