Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in CI: act(...) is not supported in production builds of React

Getting an error on CI when running jest --coverage

act(...) is not supported in production builds of React.
      80 |   describe('sample test', () => {
      81 |     it('sample', () => {
    > 82 |       component = render(<SampleComponent />);
         |                   ^

Using:

"@testing-library/react": "^13.3.0",
"jest": "26.6.3",
"jest-environment-jsdom": "26.6.2",
"jest-environment-jsdom-global": "2.0.4",

I don't understand why react-testing-library does not support testing on production. I can't seem to find anything on this.

like image 301
Jeffraux Avatar asked Oct 27 '25 09:10

Jeffraux


1 Answers

You can prefix the script that runs jest with NODE_ENV, for example:

env NODE_ENV=test jest --ci

Your CICD process is just triggering the error because the environment variable is set to production. Not actually because the files themselves were compiled in production mode.

like image 139
saltavenger Avatar answered Oct 28 '25 22:10

saltavenger