question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The current testing environment is not configured to support act(...) with React 18 & Jest

See original GitHub issue

I’m trying to upgrade my project to React 18, everything works in dev and production mode in the browser. But after upgrading to the latest version of @testing-library/react some of my unit tests are failing and a lot of them are logging the following warning:

  console.error
    Warning: The current testing environment is not configured to support act(...)

      at printWarning (node_modules/.pnpm/react-dom@18.0.0_react@18.0.0/node_modules/react-dom/cjs/react-dom.development.js:86:30)
      at error (node_modules/.pnpm/react-dom@18.0.0_react@18.0.0/node_modules/react-dom/cjs/react-dom.development.js:60:7)
      at isConcurrentActEnvironment (node_modules/.pnpm/react-dom@18.0.0_react@18.0.0/node_modules/react-dom/cjs/react-dom.development.js:25057:7)
      at warnIfUpdatesNotWrappedWithActDEV (node_modules/.pnpm/react-dom@18.0.0_react@18.0.0/node_modules/react-dom/cjs/react-dom.development.js:27351:12)
      at scheduleUpdateOnFiber (node_modules/.pnpm/react-dom@18.0.0_react@18.0.0/node_modules/react-dom/cjs/react-dom.development.js:25292:5)
      at setLoading (node_modules/.pnpm/react-dom@18.0.0_react@18.0.0/node_modules/react-dom/cjs/react-dom.development.js:17342:16)
      at _callee2$ (node_modules/.pnpm/@cubejs-client+react@0.29.51_react@18.0.0/node_modules/@cubejs-client/react/src/hooks/cube-query.js:56:7)

First thing I did was check my versions, cleared node modules and lock file just in case:

  • react 18.0.0
  • react-dom 18.0.0
  • @testing-library/react version: “13.1.1”,
  • Testing Framework and version: “jest”: “27.5.1”,
  • DOM Environment: jsdom 16.7.0

But everything looks right?

I checked the migration docs for React 18: https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html Which says the latest version of @testing-library/react shouldn’t require the globalThis.IS_REACT_ACT_ENVIRONMENT = true setting.

But I tried setting that manually anyway before my tests run. But that didn’t fix it either, (I tried several versions)

// @ts-ignore
global.IS_REACT_ACT_ENVIRONMENT = true
// @ts-ignore
globalThis.IS_REACT_ACT_ENVIRONMENT = true
// @ts-ignore
self.IS_REACT_ACT_ENVIRONMENT = true
// @ts-ignore
window.IS_REACT_ACT_ENVIRONMENT = true
// @ts-ignore
this.IS_REACT_ACT_ENVIRONMENT = true

None of those fixes the Warning or the unit tests.

I’m using jest v. 27.x with jsdom which I imagine would be the most common configuration? So I’m quite surprised to be running into this error?

Here is my jest.config

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'jsdom',
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
  moduleNameMapper: {
    '^src/(.*)$': '<rootDir>/src/$1',
    '\\.(css|less|scss|sass)$': 'identity-obj-proxy',
  },
  transform: {
    '^.+\\.(t|j)sx?$': ['ts-jest'],
  },
  setupFilesAfterEnv: ['./src/setupTests.tsx'],
  modulePathIgnorePatterns: ['src/common/config.ts'],
  coverageReporters: ['text', 'json'],
}

Any ideas why a relatively simple setup like this, would be running into this warning with RTL v. 13.1.1?

It is my understanding that with React 18.x and RTL 13.x that this warning should be handled within RTL?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:20
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
dar5hakcommented, May 7, 2022

The warning also shows up when using vitest as opposed to jest, although none of my tests fail.

I’m not using act() directly anywhere.

4reactions
stuarthallowscommented, May 7, 2022

I’ve created a repo that reproduces the error that’s logged when running the tests. The repro uses vite and vitest but the error is the same - Warning: The current testing environment is not configured to support act(…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

The current testing environment is not configured to support ...
I noticed this after switching from jest to vitest, and not changing anything else.
Read more >
The current testing environment is not configured to support ...
In my case this happened because I had a useless act that I implemented as a workaround in v12. await act(async () =>...
Read more >
How to Upgrade to React 18
The current testing environment is not configured to support act(…) To fix this, set globalThis.IS_REACT_ACT_ENVIRONMENT to true before running ...
Read more >
React Testing Library and the “not wrapped in act” Errors
…, unit test has no idea that advancing timers will cause component updates, and you will get the “not wrapped in act” error....
Read more >
Setup - Testing Library
React Testing Library does not require any configuration to be used. ... In these docs we'll demonstrate configuring Jest, but you should be ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found