-
Notifications
You must be signed in to change notification settings - Fork 128
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
instanceof doesn't work with Jest and rewire #164
Comments
I hit this same issue |
I had the same issue, so I wrote jewire. It's a niche library that clones objects and arrays at runtime solely for Jest purposes :D. Hope this helps someone out there. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
instanceof
doesn't work in Jest when being used on an object returned from Rewire. Please check out codes below.file
rewired.test.js
file
rewired.js
It turns out that Jest uses new vm context for each test to simulate a new browser window. That caused all builtins such as
Object
andArray
are created again. And for some reason, the objects created by rewire are cross-context and based on anotherObject
. So theinstanceof
test can never have correct result.Here is an example.
The result is
The text was updated successfully, but these errors were encountered: