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

Rewired function is not instanceof Function in Jest context #184

Open
sguillia opened this issue May 23, 2020 · 1 comment
Open

Rewired function is not instanceof Function in Jest context #184

sguillia opened this issue May 23, 2020 · 1 comment

Comments

@sguillia
Copy link

Hi

Here's a very simple example

index.js

function foo() { }
module.exports = { foo }

index.test.js

const rewire = require("rewire")
const index = rewire("./index")
const foo = index.foo

console.log("typeof:", typeof foo)
console.log("instanceof Function:", foo instanceof Function)

Run with Node

$ node index.test.js
typeof: function
instanceof Function: true

Run with Jest

$ jest index.test.js
...
typeof: function
instanceof Function: false
...

I'm really curious on why this happens, whether this is a bug, and how a function can be something else than an instance of Function.

@nktnet1
Copy link

nktnet1 commented Oct 12, 2023

This is related to #164.

The reason is covered in this article by Manuel Spigolon:

I wrote a niche library called jewire to work around this issue:

184

Hope this helps :).

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

No branches or pull requests

2 participants