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]: isolateModules doesn't work properly with auto mocked modules (reopen #14443) #15022

Open
Yupeng-li opened this issue Apr 8, 2024 · 0 comments

Comments

@Yupeng-li
Copy link

Version

27.2.1 & 29.6.2 & 29.6.3

Steps to reproduce

I made a mini repo to reproduce the issue. This is to reopen #14443

Expected behavior

I expect this test to pass

/* in __mocks__ folder, lodash is mocked by the file below
   lodash.ts  
*/

import * as exportsFromIndexFile from "./index";
import {range} from 'lodash'

let indexModule : typeof exportsFromIndexFile

beforeEach(()=>{
    jest.isolateModules(()=>{
        indexModule = require('./index')
    })
})

it('mocks for a library in node_modules are not working', () => {
    indexModule.helloWorld(). // helloWorld is using lodash.range inside 
    expect(range).toHaveBeenCalled()  
});

Actual behavior

But expect(range).toHaveBeenCalled() failed. It says lodash.range was not called. If I use debugger, I can see that the it's been called.

Additional context

No response

Environment

System:
    OS: macOS 13.5.1
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 18.17.0 - ~/Library/Caches/fnm_multishells/24849_1670237417415/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.6.7 - ~/Library/Caches/fnm_multishells/24849_1670237417415/bin/npm
  npmPackages:
    jest: 29.6.3 => 29.6.3
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