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: Cannot read properties of undefined (reading 'testEnvironmentOptions')

See original GitHub issue

Current Behavior

Unable to use Jest to test React Native project inside an Nx Monorepo

Expected Behavior

@nrwl/jest:jest should run all tests in the React Native project, or running one test manually should succeed (or fail) based on the test predicate.

No, this has never worked on the repo I’m working with

Steps to Reproduce

No, but couldn’t find a Typescript or React Native app in that repo.

The web app in this monorepo is able to be tested, but the React Native app fails no matter how I kick off the tests with the following error:

Failure Logs

` Test suite failed to run

TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')

  at new NodeEnvironment (../../node_modules/jest-environment-node/build/index.js:96:49)
  at async TestScheduler.scheduleTests (../../node_modules/@jest/core/build/TestScheduler.js:333:13)
  at async runJest (../../node_modules/@jest/core/build/runJest.js:404:19)
  at async _run10000 (../../node_modules/@jest/core/build/cli/index.js:320:7)
  at async runCLI (../../node_modules/@jest/core/build/cli/index.js:173:3)`

Environment

NX Report complete - copy this into the issue template

Node : 16.13.2 OS : darwin arm64 npm : 8.19.1

nx : 13.8.3 @nrwl/angular : undefined @nrwl/cli : 13.8.3 @nrwl/cypress : 13.8.3 @nrwl/detox : 13.8.3 @nrwl/devkit : 13.8.3 @nrwl/eslint-plugin-nx : 13.8.3 @nrwl/express : undefined @nrwl/jest : 13.8.3 @nrwl/js : 13.8.3 @nrwl/linter : 13.8.3 @nrwl/nest : undefined @nrwl/next : undefined @nrwl/node : undefined @nrwl/nx-cloud : undefined @nrwl/react : 13.8.3 @nrwl/react-native : 13.8.3 @nrwl/schematics : undefined @nrwl/storybook : 13.8.3 @nrwl/tao : 13.8.3 @nrwl/web : 13.8.3 @nrwl/workspace : 13.8.3 typescript : 4.4.4 rxjs : 6.6.7

Community plugins:

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
coderroggiecommented, Oct 3, 2022

I have fixed my issue by adding and pinning the versions of jest-environment-node and jest-config to the same version as jest.

    "jest": "27.5.1",
    "jest-environment-node": "27.5.1",
    "jest-config": "27.5.1",
2reactions
rexkenleycommented, Sep 9, 2022

I am experiencing the same issue. My current workaround is to delete the testEnvironment property in jest.config.

I also tried jest-environment-jsdom and jest-environment-node, they didn’t work. listed in the documentation

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest: testEnvironmentOptions cannot be read - Stack Overflow
Jest: testEnvironmentOptions cannot be read ... TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions') at new ...
Read more >
Jest: Cannot read properties of undefined (reading ...
The Jest "TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')" occurs for 2 main reasons: Having incompatible versions of jest and ...
Read more >
cannot read property 'testenvironmentoptions' of undefined
TypeError : Cannot read properties of undefined (reading 'testEnvironmentOptions') at new NodeEnvironment (node_modules/jest-environment-node/build/index.js:96: ...
Read more >
jest-environment-jsdom | Yarn - Package Manager
... [@jest/reporters] Fix Cannot read property converageData of null (#8168) ... [expect] Fix TypeError in toBeInstanceOf on null or undefined (#6912) ...
Read more >
Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
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