Skip to content

[Bug]: jest.resetModules does not works for jest.unstable_mockModule #15079

@BondarenkoAlex

Description

@BondarenkoAlex

Version

29.7.0

Steps to reproduce

package.json

  "scripts": {
    "test": "NODE_OPTIONS=--experimental-vm-modules jest",
  },

test.js

import {jest, test} from "@jest/globals";

test("test", async () => {
  jest.unstable_mockModule("@commitlint/load", () => ({
    default: jest.fn(),
  }));
  const mockModule = await import("@commitlint/load");
  jest.resetModules();
  const originalModule = await import("@commitlint/load");
  console.log(originalModule);
});

Expected behavior

console.log
    [Module: null prototype] {
      default: [AsyncFunction: load],
      resolveFrom: [Function: resolveFrom],
      resolveFromSilent: [Function: resolveFromSilent],
      resolveGlobalSilent: [Function: resolveGlobalSilent]
    }

Actual behavior

console.log
    [Module: null prototype] {
      default: [Function: mockConstructor] {
        _isMockFunction: true,
        getMockImplementation: [Function (anonymous)],
        mock: [Getter/Setter],
        mockClear: [Function (anonymous)],

Additional context

Related issue - #12617
Related issue - #13448

Environment

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 16.20.1 - ~/.nvm/versions/node/v16.20.1/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v16.20.1/bin/yarn
    npm: 10.6.0 - ~/Documents/Bond/semantic-release-commits-lint/node_modules/.bin/npm
    pnpm: 8.14.1 - ~/.nvm/versions/node/v16.20.1/bin/pnpm
  npmPackages:
    jest: ^29.7.0 => 29.7.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions