Skip to content

Cannot use dont-cleanup-after-each in browser #1131

Open
@IanVS

Description

@IanVS
  • @testing-library/react version: 13.3.0
  • Testing Framework and version: Storybook 6.5.9
  • DOM Environment: Browser

Relevant code or config:

import '@testing-library/react/dont-cleanup-after-each';

What you did:

I'm trying to update to react 18, but am getting errors about act not being available in production builds of react. So, I tried setting globalThis.IS_REACT_ACT_ENVIRONMENT = false, but found that this library automatically sets it to true, so to disable it I tried to import dont-cleanup-after-each as instructed in https://testing-library.com/docs/react-testing-library/setup#skipping-auto-cleanup, since testing-library/react-testing-library#994 said to disable it the same way as cleanup.

What happened:

Uncaught ReferenceError: process is not defined
    at dont-cleanup-after-each.js:1:1

This is because process does not exist in browsers, which is where I'm running RTL.

Reproduction:

Problem description:

I can't disable the use of ACT, it seems, which causes my tests to fail.

Suggested solution:

If process is not defined, you could check for import.meta.env and use that instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions