TS-Jest utils missing
Asked Answered
P

3

25

Well, using ts-jest 27.x.x, I could access the utils helper by require('ts-jest/utils'), and as you can see in the below picture, it was present in the ts-jest dependency folder: ts-jest 27

But in a newer project using ts-jest 28.x.x, when I try to import that, this is the result: error import

And this is the ts-jest dependency folder: ts-jest 28

What should I do now to use those helpers?

Paleogeography answered 13/7, 2022 at 2:53 Comment(0)
I
45

See Test helpers doc about the mocked test helper:

This function is now deprecated and will be removed in 28.0.0. The function has been integrated into jest-mock package as a part of Jest 27.4.0, see https://github.com/facebook/jest/pull/12089. Please use the one from jest-mock instead.

You should use jest.mocked(item: T, deep = false) instead of import { mocked } from 'ts-jest/utils'

From ts-jest 28.0.0, they remove ts-jest/utils sub path export. See this issue

We are exporting everything from index.ts so utils now can be removed.

Indeterminable answered 13/7, 2022 at 3:30 Comment(1)
I was actually looking for the pathsToModuleNameMapper method which was available in ts-jest/utils, however just like you said, it is indeed available in the index :D thank you my friend!Selfabasement
D
6

Replace

import { mocked } from "ts-jest/utils";

with

import { mocked } from "jest-mock";
Daiseydaisi answered 28/7, 2023 at 15:17 Comment(0)
D
1

Did you try putting that file in the setupFilesAfterEnv option in the jest config?

Deweydewhirst answered 13/7, 2022 at 3:8 Comment(2)
no need for that. as our friend @slideshowp2 said, everything i needed from /utils was actually available in the ts-jest itself.Selfabasement
Cool. Very helpful post!Deweydewhirst

© 2022 - 2024 — McMap. All rights reserved.