React-testing-library: Cleanup not happening when using configure from @testing-library/react

Created on 11 May 2020  路  1Comment  路  Source: testing-library/react-testing-library

  • @testing-library/react version:"10.0.4"
  • Testing Framework and version:"jest": "26.0.1"
  • DOM Environment:"@testing-library/jest-dom": "5.7.0"

Relevant code or config:

What you did:

Using with jest with a setup file having just import { configure } from "@testing-library/react"; with simple component


testing a component by using getByTestId

What happened:

In the second test, getting the error Found multiple elements by: [data-testid="myinputtest"]
but when I un-comment import statement from the config file, it is passing.


image

Reproduction:

Codesandbox url: https://codesandbox.io/s/rtl-test-c8hj6
It is not failing in codesandbox but can reproduce by exporting as zip and trying in local

  1. Download this repo.
  2. Do 'npm i'
  3. Do 'npm run start'

Problem description:


Cleanup is not happening, can't select by using data-testid

Most helpful comment

Hi @krajasekhar,

Here's the fix (in the jest config of package.json):

"setupFiles": [
  "react-app-polyfill/jsdom"
],
"setupFilesAfterEnv": [
  "<rootDir>/config/jest/testingLibraryConfig.js"
],

Move the config to the setupFilesAfterEnv config because we require the jest environment to be setup to get the auto-cleanup functionality working.

Good luck!

>All comments

Hi @krajasekhar,

Here's the fix (in the jest config of package.json):

"setupFiles": [
  "react-app-polyfill/jsdom"
],
"setupFilesAfterEnv": [
  "<rootDir>/config/jest/testingLibraryConfig.js"
],

Move the config to the setupFilesAfterEnv config because we require the jest environment to be setup to get the auto-cleanup functionality working.

Good luck!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chasen-bettinger picture chasen-bettinger  路  3Comments

AirborneEagle picture AirborneEagle  路  3Comments

julienw picture julienw  路  4Comments

bdauria picture bdauria  路  4Comments

suresh777 picture suresh777  路  3Comments