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.

ReferenceError: spyOn is not defined after migration to 12.4.0

See original GitHub issue

Current Behavior

After migration from 12.3.6 to 12.4.0 (jest is bumped to 27) I get ReferenceError: spyOn is not defined on every spyOn occurence in my tests

Expected Behavior

After migration I would expect that test would work as before (compile & execute successfully).

Steps to Reproduce

Migrate from 12.3.6 to 12.4.0

Failure Logs

    ReferenceError: spyOn is not defined

      38 |
      39 |     const item = mockItems[1];
    > 40 |     spyOn(instance.selected, 'emit');

Environment

It is happening when running test e.g. nx affected:test

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

26reactions
russcarvercommented, Nov 14, 2021

Since I’m using Jasmine tests under Jest, I solved this by adding the following to jest.config.js:

  testRunner: 'jest-jasmine2',

See: https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults

10reactions
shumihcommented, Jun 18, 2021

This method and many other jasmine methods were removed in jest 27. You should replace usage of spyOn with jest.spyOn (https://jestjs.io/docs/jest-object#jestspyonobject-methodname)

Read more comments on GitHub >

github_iconTop Results From Across the Web

spyon is not defined jest | The AI Search Engine You Control
After migration from 12.3.6 to 12.4.0 (jest is bumped to 27) I get ReferenceError: spyOn is not defined on every spyOn occurence in...
Read more >
Jest - ReferenceError: spyOn is not defined - Stack Overflow
For spyOn i am getting. ReferenceError: spyOn is not defined. So changed it to jest.spyOn but now I am getting the error:.
Read more >
'spyOn' is not defined.eslint(no-undef) - DEV Community ‍ ‍
That happens even after installing the @types/jest package. ESLint needs you to specify which environments your script will run: // .eslintrc.
Read more >
How to migrate from jasmine to jest - LeanIX Engineering Blog
This could mean that a spy is not restored during testing. It could be fixed by calling jest.restoreAllMocks() in an afterEach() block.
Read more >
npm ERR! peer react@"^17.0.0" from react-github-calendar ...
“npm ERR! Could not resolve dependency: npm ERR! peer react@"^17.0.0" from react-github-calendar@3.3.1” Code Answer's. Could ...
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