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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

mocked no longer works for jest 27.1 with isolateModules #2898

Closed
rburgst opened this issue Sep 16, 2021 · 2 comments
Closed

mocked no longer works for jest 27.1 with isolateModules #2898

rburgst opened this issue Sep 16, 2021 · 2 comments
Labels
Not An Issue Not ts-jest issue

Comments

@rburgst
Copy link

rburgst commented Sep 16, 2021

馃悰 Bug Report

after upgrading from jest 27.0.6 to 27.2.0 (also fails with 27.1.1) the following code no longer invokes the mocked function

import { mocked } from "ts-jest/utils";
import * as config from "../config";

jest.mock("../config");

  it("should be able to override getBoolean", () => {
    const configGetMock = mocked(config.getBoolean).mockImplementation(() => {
      console.log("called mock");
      return true;
    });

    jest.isolateModules(() => {
      require("../uses-config");
    });

    expect(configGetMock).toBeCalledTimes(1);
  });

To Reproduce

see https://github.com/rburgst/ts-jest-27.1

Steps to reproduce the behavior:

just check out the repo and run

yarn install
yarn test

Expected behavior

if you load a file in the test using jest.isolateModules then as of jest 27.1.0 this no longer works together with a mocked method.

Link to repo (highly encouraged)

https://github.com/rburgst/ts-jest-27.1

Debug log:

ts-jest.log

envinfo

System:
    OS: Mac OSX 
    Node version: 14.16

Npm packages:
    jest: 27.2.0
    ts-jest: 27.0.5
    typescript: 4.4.3
    babel(optional):
@rburgst rburgst added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Sep 16, 2021
@rburgst
Copy link
Author

rburgst commented Sep 16, 2021

hm, might be a jest issue, see jestjs/jest#11873

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 16, 2021

this is Jest issue :)

@ahnpnl ahnpnl closed this as completed Sep 16, 2021
@ahnpnl ahnpnl added Not An Issue Not ts-jest issue and removed Needs Repo Need a minimium repository to reproduce the problem Bug Report Needs Triage labels Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not An Issue Not ts-jest issue
Projects
None yet
Development

No branches or pull requests

2 participants