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.

TypeError: TestEnvironment is not a constructor in combination with Enzyme

See original GitHub issue

With Enzyme installed, running tests:

"test": "react-scripts test --env=jsdom"

Throws the error:

TypeError: TestEnvironment is not a constructor
at runTest (node_modules/react-scripts/node_modules/jest/node_modules/jest-cli/build/runTest.js:30:15)

The tests run correctly when removing --env=jsdom.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Sep 2, 2016

We’re going to cut a patch fixing this today but for now, you can work around it by opening node_modules/react-scripts/node_modules/jest-config/build/normalize.js and commenting out lines 80 to 90.

0reactions
gaearoncommented, Sep 2, 2016

I fixed this locally by commenting these lines out. In case of Create React App it is incorrect to resolve relative to rootDir because that’s not where Jest is. It should try require.resolve() first—at least for our use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot create custom TestEnvironment in Jest - Stack Overflow
I am trying to create a custom test environment with Jest as described in their official ... TypeError: TestEnvironment is not a constructor...
Read more >
Doc TypeError in Jest test environment - Yjs Community
Hello everyone, I am trying to test yjs with Jest. Unfortunately I was not able to get an initial test running because of...
Read more >
Configuring Jest
If a given module's path matches any of the patterns, it will not be require() -able in the test environment. These pattern strings...
Read more >
jest-environment-jsdom | Yarn - Package Manager
Jest uses verbose mode when running a single test file. Console messages are now buffered and printed along with the test results. Fix...
Read more >
Setup - Testing Library
React Testing Library does not require any configuration to be used. However, ... querySelector or a combination of existing
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