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.

jest is not defined

See original GitHub issue

While trying to use this package i receive this error:

ReferenceError: jest is not defined
    at Object.<anonymous> (/myProject/node_modules/jest-fetch-mock/src/index.js:49:15)

Do you have any idea how to fix this? Is this related to this project peer-dependencies?

Thanks in advance!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:16
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
anvlkvcommented, Feb 3, 2020

I have the same error.

package versions:

jest: v24.9.0
jest-fetch-mock: v2.1.2

jest.config.js (left details out, can reproduce with just this)

module.exports = {
  globalSetup: './tests/jest-setup.js'

tests/jest-setup.js

const fetch = require('jest-fetch-mock')

// details left out - error throw inside `jest-fetch-mock` with just this

The error occurs inside jest-fetch-mock/src/index.js on line 49. There is a reference to jest but no import for it.

seems it should be

 setupFiles: [
    './__test__/jest-setup.ts'
  ],

not globalSetup

1reaction
tctc91commented, Jul 30, 2021

Had this after upgrading to Next 11. My setup had collocated test & implementation files which I had working via webpack’s IgnoreLoader plugin. This plugin had a breaking change in Webpack 5.

config.plugins.push(new webpack.IgnorePlugin(/\.(e2e|spec).(ts|tsx)$/))

to

config.plugins.push(new webpack.IgnorePlugin({ resourceRegExp: /\.(e2e|spec).(ts|tsx)$/ }))
Read more comments on GitHub >

github_iconTop Results From Across the Web

'ReferenceError: jest is not defined' when running unit test
I notice that if I do not specify jest-environment-node as my test environment, the error changes to ReferenceError: global is not defined due ......
Read more >
Jest is not defined · Issue #22 - GitHub
Error msg: ReferenceError: jest is not defined at Object.
Read more >
Configuring Jest
It is recommended to define the configuration in a dedicated JavaScript, TypeScript or JSON file. The file will be discovered automatically, if ...
Read more >
jest referenceerror: global is not defined - You.com
Make sure the path to test-env.js is correct from your root directory. <rootDir> is available in Jest. Open side panel.
Read more >
From Jest to Vitest - Migration and Benchmark
describe is not defined. Well, Jest has these globals declared, but it seems that Vitest does not, and we need to import them...
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