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

ReferenceError: spyOn is not defined after migration to 12.4.0 #6063

Closed
dragonflypl opened this issue Jun 17, 2021 · 9 comments
Closed

ReferenceError: spyOn is not defined after migration to 12.4.0 #6063

dragonflypl opened this issue Jun 17, 2021 · 9 comments
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@dragonflypl
Copy link

dragonflypl commented Jun 17, 2021

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

@shumih
Copy link

shumih commented 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)

@dragonflypl
Copy link
Author

Are you planning to add a migration for it in next versions?

@FrozenPandaz FrozenPandaz added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Jun 25, 2021
@d3473r
Copy link
Contributor

d3473r commented Sep 13, 2021

Any update on this issue?

I am getting the same error and some more after going from jest 26 to 27 with nx migrate latest
I am currently collecting all jest related errors (an missing migrations) below:

  • ReferenceError: fail is not defined, related issue: [jest-circus] missing fail() method jestjs/jest#11698
  • Property 'and' does not exist on type 'SpyInstance' after changing from spyOn to jest.spyOn
  • thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

@gabeodessru
Copy link

Property 'and' does not exist on type 'SpyInstance' after changing from spyOn to jest.spyOn

I'm having the same issue.

@russcarver
Copy link

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

@mmruesch12
Copy link

Property 'and' does not exist on type 'SpyInstance' after changing from spyOn to jest.spyOn

I'm having the same issue.

I'm having the same issue right now as well. Did anybody find a solution for this? I'm hoping I don't have to manually fix a large amount of tests.

@gabeodessru
Copy link

I'm having the same issue right now as well. Did anybody find a solution for this? I'm hoping I don't have to manually fix a large amount of tests.

If you are trying to find a solution to .and.return() you could do a find and replace with .mockResolvedValue()

@mmruesch12
Copy link

I'm having the same issue right now as well. Did anybody find a solution for this? I'm hoping I don't have to manually fix a large amount of tests.

If you are trying to find a solution to .and.return() you could do a find and replace with .mockResolvedValue()

Probably won't be able to get away with a find and replace but that did work for me. Thanks!

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

8 participants