jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.16k stars 6.45k forks source link

[Bug]: Cannot read property 'bind' of undefined #12182

Closed PierreTurnbull closed 2 years ago

PierreTurnbull commented 2 years ago

Version

27.4.5

Steps to reproduce

Just run a simple test with nothing in it:

test("a", () => {
})

Expected behavior

Not getting this error, and the test should work.

Actual behavior

 FAIL  tests/jest/integration/promoCodeTemplateEditor.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'bind' of undefined

      at Runtime._createJestObjectFor (node_modules/@jest/core/node_modules/jest-runtime/build/index.js:2193:46)
      at async TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
Capture d’écran 2021-12-22 à 18 02 06

Additional context

The error doesn't show up on 26.6.3. I'll use this version until the bug is fixed.

Probably related issue: https://github.com/facebook/jest/issues/11720

Environment

MacOS Big Sur v11.4
node v14.17.0
npm 6.14.13
jest 27.4.5
bboydflo commented 2 years ago

I've got the same after an update from jest version 27.4.3

falconbin commented 2 years ago

I have the same issue running in jenkins pipeline(probably ubuntu) for both version ^27.0.6 and ^27.4.5, but works in my local mac.

SimenB commented 2 years ago

Please provide a reproduction we can run and see the error

falconbin commented 2 years ago

This issue happens on ubuntu, mac works fine. On ubuntu:

"jest": "^26.0.1", "ts-jest": "^26.0.0",

works fine, but when I upgrade to

"jest": "^27.0.6", "ts-jest": "^27.0.4",

all the UT failed with error: image

SimenB commented 2 years ago

Again, a reproduction is needed

falconbin commented 2 years ago

I tried to reproduce the issue with minimum dependencies, but failed, everything works fine. And finally I found that my issue relates to mono repo as we use lerna.

falconbin commented 2 years ago

I tried to reproduce the issue with minimum dependencies, but failed, everything works fine. And finally I found that my issue relates to mono repo as we use lerna.

use yarn install instead of npm install solved my issue

bboydflo commented 2 years ago

I am trying to identify the issue too. I am using jest in a npm@8 workspaces setup and I think the issue might be due to an update of a different package that depends on jest. I think one issue could be the resulting package-lock.json after I attempt to update a package that indirectly depends on an older version of jest. still investigating

UPDATE: I've tried to update every dependency one by one and unfortunately the last one is jest and bumping it from 27.4.3 to 27.4.5 produces the same error. I run jest via ts-jest and I suspect it has to be something to do with how jest is being ran.

This is roughly my folder structure

+ root
    - package.json
    - package-lock.json
    + node_modules
    + packages
          + backend
          + frontend

The errors I get are from running tests inside the backend npm workspace.

My jest.config.js

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
};

and the error:

#20 16.75 FAIL src/utils/sanitization-utils.test.ts
#20 16.75   ● Test suite failed to run
#20 16.75
#20 16.75     TypeError: Cannot read property 'bind' of undefined
#20 16.75
#20 16.75       at Runtime._createJestObjectFor (../../node_modules/jest-runtime/build/index.js:2193:46)
#20 16.75       at async TestScheduler.scheduleTests (../../node_modules/@jest/core/build/TestScheduler.js:333:13)
#20 16.75       at async runJest (../../node_modules/@jest/core/build/runJest.js:404:19)
laat commented 2 years ago

I get this error with @types/jest-environment-puppeteer which has a dependency "jest-environment-node": ">=24 <=26".

repro

bboydflo commented 2 years ago

@laat it seems to be working if you update to latest jest. I've just tried that.

updating to last version of jest (27.4.6) also fixed my issue.

SimenB commented 2 years ago

Yeah, fixed by #12213

github-actions[bot] commented 2 years ago

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.