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 and Array are created again. And for some reason, the objects created by rewire are cross-context and based on another Object. So the instanceof test can never have correct result.
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