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

[Bug]: resetModules breaks instanceof #15258

Closed
kb-ig opened this issue Aug 15, 2024 · 3 comments
Closed

[Bug]: resetModules breaks instanceof #15258

kb-ig opened this issue Aug 15, 2024 · 3 comments

Comments

@kb-ig
Copy link

kb-ig commented Aug 15, 2024

Version

29.7.0

Steps to reproduce

Clone repo:

git clone https://github.com/kb-ig/jest-instanceof-resetmodules

Install package:

npm install

Run test:

npm run test

Expected behavior

I would have thought the instanceof operator should remain unaffected following a call to jest.resetModules().

Actual behavior

The following test starts failing after a call to jest.resetModules().

// someModule.js
function isSomeClass(thing) {
    return thing instanceof SomeClass;
}

// someModule.test.js
const SomeClass = require('./SomeClass');

test('resetModules, instanceof', () => {
    const before = require('./someModule');
    const thing = new SomeClass();
    expect(before.isSomeClass(thing)).toBe(true); // pass

    jest.resetModules();

    const after = require('./someModule');
    expect(after.isSomeClass(thing)).toBe(true); // fail
})

The instanceof operator cannot correctly determine that an object is an instance of a certain class after calling jest.resetModules()

Additional context

No response

Environment

System:
    OS: Linux 6.5 Zorin OS 17.1 17.1
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v18.18.2/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Sep 19, 2024
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2024
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

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

No branches or pull requests

1 participant