ReferenceError: spyOn is not defined after migration to 12.4.0
See original GitHub issueCurrent 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:
- Created 2 years ago
- Reactions:1
- Comments:8 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Since I’m using Jasmine tests under Jest, I solved this by adding the following to
jest.config.js
:See: https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults
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)