Skip to content

[Bug]: issue with jest-runtime between 27.1.0 and 27.1.1 and jest.isolateModulesΒ #11873

@vidarc

Description

@vidarc

Version

27.2.0

Steps to reproduce

unable to link my repo, but can give an example that currently works. seems how mocks are applied changed between 27.1.0 and 27.1.1. assume related to this PR: #11818

Expected behavior

const someModule = require('some-module');

jest.mock('some-module')

describe('test', () => {
  let app;
  beforeEach(() => {
    jest.isolateModules(() => {
      app = require('./app.js')
    })
  })

  test('expect module to have been called', () => {
    expect(someModule.function).toHaveBeenCalled();
  })
})

I would expect this to pass, which is currently does if I pass in a yarn resolution to downgrade jest-runtime to version 27.1.0.

Actual behavior

Using above example, the instance of some-module inside of the test and inside the required file appear to be different. Inside the file, the module is indeed mocked, but the expectation does not pass.

Additional context

No response

Environment

System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
  Binaries:
    Node: 14.17.6 - /usr/local/bin/node
    Yarn: 1.22.11 - /usr/local/bin/yarn
    npm: 7.21.1 - /usr/local/bin/npm
  npmPackages:
    jest: 27.2.0 => 27.2.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