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

mock mockReturnValue doesn't work #95

Open
Gennady77 opened this issue May 8, 2022 · 2 comments
Open

mock mockReturnValue doesn't work #95

Gennady77 opened this issue May 8, 2022 · 2 comments

Comments

@Gennady77
Copy link

I use last version of React and try to write test in Jest:

const getItemSpy = jest.spyOn(localStorage, 'getItem');
getItemSpy.mockReturnValue(null);

and got error:
TypeError: getItemSpy.mockReturnValue is not a function

If I run:
console.log(getItemSpy.mockReturnValue);

It shows undefined

What's the problem?

@Smrtnyk
Copy link
Contributor

Smrtnyk commented May 8, 2022

This has nothing to do with swc, its jest issue
you need to spy on LocalStorage.prototype

@Smrtnyk
Copy link
Contributor

Smrtnyk commented May 8, 2022

also mockReturnvalue is a setter, not sure if that will return anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants