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.

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:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:14

github_iconTop GitHub Comments

14reactions
SimenBcommented, Feb 8, 2020

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)

4reactions
SimenBcommented, Mar 26, 2020

I’ve published 25.2.2 which has a workaround for this issue on the buggy versions of node

Read more comments on GitHub >

github_iconTop 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 >

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