Skip to content

Rewired function is not instanceof Function in Jest context #184

@sguillia

Description

@sguillia

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions