Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing jest returns undefined - TypeError: Cannot read property 'run' of undefined #8080

Closed
blackdynamo opened this issue Mar 7, 2019 · 2 comments · Fixed by #8081
Closed

Comments

@blackdynamo
Copy link

💥 Regression Report

The switch to use Typescript introduced a regression in a minor version change.

9fa3268#diff-153503da41d156755e19c0aedcd2eb43R10

The change is now throwing an error:

TypeError: Cannot read property 'run' of undefined

The actual default export of jest no longer has anything on it. Users now have to import the exact named exports. To work around the issue, you must now do this:

import * as jest from "jest";

console.log(jest);
console.log(jest.getVersion());

// or

import {getVersion} from "jest";

console.log(getVersion());

NOTE: This is specific you using ES6 import

Last working version

Worked up to version: 24.0.0 & 24.1.0

Stopped working in version: 24.3.0

To Reproduce

See included repo link below:

import jest from "jest";

console.log(jest);
console.log(jest.getVersion());

Expected behavior

Expected jest to be defined, but it's undefined.
Expected jest to look like this:

{ SearchSource: [Function: SearchSource],
  TestScheduler: [Function: TestScheduler],
  TestWatcher: [Function: TestWatcher],
  getVersion: [Function: getVersion],
  run: [Function: run],
  runCLI: [Function: runCLI] }

Link to repl or repo (highly encouraged)

https://github.com/blackdynamo/jest-24.3.0-import-regression

24.1.0 Working
image

24.3.0 Not Working
image

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.3
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  Binaries:
    Node: 10.15.2 - ~/.nvm/versions/node/v10.15.2/bin/node
    npm: 6.4.1 - ~/.nvm/versions/node/v10.15.2/bin/npm
  npmPackages:
    jest: 24.3.0 => 24.3.0 
@SimenB
Copy link
Member

SimenB commented Mar 7, 2019

Thanks for the report! I've opened up #8081 which fixes it.

However, I recommend you to do import {run} from 'jest' - it doesn't really have a default export. Also see #5048 for discussions about a programmatic API

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants