jest: TypeError: environment.teardown is not a function at node_modules/jest-runner/build/run_test.js
š Bug Report
Hello, I have used create React app and canāt make the tests work. Initially, I got an error message with jest and jest-cli so installed jest with npm install --save-dev jest and then jest-cli with npm install jest-cli. However, I still get the following message: Test suite failed to run TypeError: environment.teardown is not a function at node_modules/jest-runner/build/run_test.js
Run npx envinfo --preset jest
Paste the results here: System: OS: macOS High Sierra 10.13.2 CPU: x64 Intel® Core⢠i5-5350U CPU @ 1.80GHz Binaries: Node: 9.4.0 - ~/.nvm/versions/node/v9.4.0/bin/node Yarn: 1.6.0 - /usr/local/bin/yarn npm: 6.1.0 - ~/.nvm/versions/node/v9.4.0/bin/npm npmPackages: jest: ^23.1.0 => 23.1.0
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 17
- Comments: 44 (2 by maintainers)
Commits related to this issue
- Attempt to fix Jest in CI conforming to https://github.com/facebook/jest/issues/6393#issuecomment-399992545 — committed to code-star/codestar-website-react by mdvanes 6 years ago
- Reinstall modules to fix test framework Followed these instructions: https://github.com/facebook/jest/issues/6393#issuecomment-399696373 — committed to cheshire137/competiwatch-desktop by cheshire137 6 years ago
- Remove yarn-cli We're not supposed to install it explicity <sigh>. Installing it is not a fix for the "environment.teardown is not a function" error. This is: https://github.com/facebook/jest/issues... — committed to PTFS-Europe/koha-react by deleted user 6 years ago
- Fix error when running tests Got this error when I ran `npm test`: > TypeError: environment.teardown is not a function Followed this advice: https://github.com/facebook/jest/issues/6393#issuecommen... — committed to cheshire137/competiwatch-desktop by cheshire137 5 years ago
I managed to make it work after deleting package-lock.json, yarn.lock, node_modules, removing jest from the dependencies in package.json, then doing npm install and yarn install!
Before I could run the tests though the script was complaining that it was missing the jest-cli.
I installed that, then got this error.
If you use CRA, you shouldnāt install Jest yourself - it comes with CRA out of the box š
See e.g. https://github.com/facebook/jest/issues/5119#issuecomment-356120965
Thanks, @revanthCopart! I managed to get back on track by doing the following steps:
Delete package-lock.json, yarn.lock, node_modules.
Deleting jest from package.json didnāt help me because
npm installandyarn installre-installed 2 versions of jest when inspecting package-lock.json. I removed jest and jest-cli completely by:npm uninstall jest jest-cliandyarn remove jest jest-cli.npm installthenyarn install.At this point, I have the issue mentioned in #1767.
brew install watchmanfixed it. šI am using jest version 21.2.1. In my case I had to install
jest-cli 21.2.1in order to fix this@yoryos
jest-clifrom your deps*.lockfiles,node_modulesyarn installornpm i, relates from you using tool.Following the above steps but using version
20.0.4worked for me.npm installI had to also install
jest-clias without doing so I got the error as documented below. But hereās the kicker - it could not find my tests (0 matches) after doing so. Iāve never had trouble with jest/cra on windows like this until this most recent project.Error Stack
Environment
yarn1.3.2npm6.1.0nodev9.9.0create-react-app1.5.2react-scripts1.1.4EDIT: Solved Precisely as in https://github.com/facebook/jest/issues/6393#issuecomment-399615757 everything worked after installing
jest-cli@20.0.4Do not simply run
npm install --save-dev jest-clias ^23 will be installed and things will still break.Again, donāt install Jest if you use CRA
@louishoang I had to install
jest-cliversion20.0.4.For me a workaround was removing the config option
testEnvironment: 'node'. Is the node test environment not bundled in the latest jest?Same issue with clean CRA.
FAIL src/App.test.js ā Test suite failed to run
Ran npx envinfo --preset jest System: OS: macOS High Sierra 10.13.3 CPU: x64 Intel® Core⢠i7-6700HQ CPU @ 2.60GHz Binaries: Node: 8.9.1 - ~/.nvm/versions/node/v8.9.1/bin/node Yarn: 1.3.2 - /usr/local/bin/yarn npm: 5.5.1 - ~/.nvm/versions/node/v8.9.1/bin/npm npmPackages: jest: ^23.1.0 => 23.1.0
@pwlmaciejewski thank you for that.
I was encountering this using an ejected CRA (without typescript) where I had
npm i jest-cliafter ejecting.When I aligned my versions of
jestandjest-clijest started successfully.Just FYI.
In my TS project that doesnāt use CRA I was getting
The solution was to align
jestwithts-jestMAJOR.MINOR and installjest-cliwith matching version:The higher version of
jest-cliwas throwing the error.This problem is coming up again.
I removed yarn.lock, package-lock.json and node_modules I have no jest dependency in package.json with yarn it installs version 20.0.3 of jest-environment-jsdom (and problem occurs) with npm version 23.4.0 is installed and no more problems.
Before installing jest and jest-cli and I had exact the same error as @louishoang.
Now Iām having the āTypeError: environment.teardown is not a functionā issue.
Iām running OSX 10.12.6
try this https://stackoverflow.com/a/52118404/9074387
Worked when I used the same jest version as the react scripts jest version. Which in my case is
20.0.4. Lot of them mentioned that we should not be installing jest ourselves since it comes withreact-scriptsbut that didnāt work for me.Same issue for me with or without standalone Jest. I tried @FaabLondon 's suggestion but no luck. The issue tends to happen after installing a new package.
System: OS: macOS High Sierra 10.13.5 CPU: x64 Intel® Core⢠i7-7700HQ CPU @ 2.80GHz Binaries: Node: 10.3.0 - ~/.nvm/versions/node/v10.3.0/bin/node Yarn: 1.7.0 - /usr/local/bin/yarn npm: 6.1.0 - ~/Desktop/maximax/wada-front/node_modules/.bin/npm npmPackages: jest: ^23.1.0 => 23.1.0
Was able to fix using @FaabLondonās suggestion above.