setting testEnvironment to node causes jest functions to be undefined
See original GitHub issue🐛 Bug Report
When setting testEnvironment to node and running a test I get ReferenceError: test is not defined. If I remove testEnvironment: 'node' from the config it runs fine. The same applies to describe, beforeAll…etc.
Note: it works fine on node 10.16.0
FAIL test/1.test.js
● Test suite failed to run
ReferenceError: test is not defined
> 1 | test('test1', () => {
| ^
2 | expect(1).toBe(1);
3 | });
at Object.<anonymous> (test/1.test.js:1:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.333s
Ran all test suites.
npm ERR! Test failed. See above for more details.
To Reproduce
Steps to reproduce the behavior:
jest.config.js
module.exports = {
testEnvironment: 'node'
}
test/1.test.js
test('test1', () => {
expect(1).toBe(1);
});
Expected behavior
Tests should run without errors when testEnvironment is set to node.
Link to repl or repo (highly encouraged)
envinfo
System:
OS: macOS 10.15.3
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 10.14.0 - /usr/local/bin/node
npm: 6.13.7 - /usr/local/bin/npm
npmPackages:
jest: ^25.1.0 => 25.1.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:14
Top Results From Across the Web
Configuring Jest
Default: undefined. This option allows the use of a custom dependency extractor. It must be a node module that exports an object with...
Read more >Why Jest is not letting me use node testing environment even ...
I need to use the Node environment and they are not letting me. I am receiving the following error: ○ basic test The...
Read more >Testing with Node, Jest, and JSDOM - Manning Publications
In this article, you'll learn how to use Node and Jest to test code ... "jsdom" to Jest's testEnvironment option, you can make...
Read more >Setup - Testing Library
In these docs we'll demonstrate configuring Jest, but you should be able to do similar things with any testing framework (React Testing ...
Read more >Configuring Jest compiled - w3resource
Jest's configuration can be defined inside the package.json file of your ... The resolver has to be a node module that exports a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Right, that’s a bug in node 10.14.0 and 10.14.1 (possibly earlier as well, didn’t check) - 10.14.2 (and newer) works correctly. Fix is https://github.com/nodejs/node/pull/23206.
(duplicate of #9453)
I’ve published 25.2.2 which has a workaround for this issue on the buggy versions of node