A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
Questions tagged [ts-jest]
1505 questions
20
votes
5 answers
The current testing environment is not configured to support act(...) - @testing-library/react
I'm trying to upgrade my project to React 18, everything works in dev and production mode in the browser. But after upgrading to the latest version of @testing-library/react some of my unit tests are failing and a lot of them are logging the…

MLyck
- 4,959
- 13
- 43
- 74
19
votes
7 answers
"ReferenceError: structuredClone is not defined" using jest with nodejs & typescript
I'm running tests with jest in a simple NodeJS app that uses typescript. My test is throwing an error: ReferenceError: structuredClone is not defined.
I'm not getting any linter errors and the code compiles fine normally.
const…

JimmyTheCode
- 3,783
- 7
- 29
- 71
19
votes
5 answers
NestJS Jest cannot find module with absolute path
I have a quite new NestJS application. I'm trying to run unit tests, but they keep failing due to 'cannot find module..' when using absolute paths ("src/users/..."), but works when using relative paths ("./users/.."). Is there anything wrong with my…

Chris Eikrem
- 496
- 1
- 5
- 20
18
votes
4 answers
Jest encountered an unexpected token + react markdown
I'm getting an error when trying to run my test file (I'm using react typescript)
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use…

ng-someone
- 321
- 2
- 9
18
votes
4 answers
Uncaught TypeError: Cannot read properties of undefined (reading 'isBatchingLegacy')
I am trying to test a react typescript project using jest but it's giving a confusing error:
Error image
Here is my package.json:
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.5",
…

Sadman Yasar Sayem
- 851
- 1
- 5
- 10
17
votes
2 answers
Vuetify Jest Unknown custom element
I am writing unit tests for my project, using Jest. Project is based on Vue, Vuetify (1.5) and TypeScript (and vue-property-decorator).
I have basic wrapper for . It looks like this:

KingGary
- 628
- 6
- 16
17
votes
1 answer
Visual Studio Code won't properly step on TypeScript code
I am trying to configure Visual Studio Code to use TypeScript (in a Node package), I'm also using ts-jest/Jest to create tests, additionally, I have the Jest extension installed.
I have been able to figure out how to make breakpoints work, but now I…

Pop Flamingo
- 3,023
- 2
- 26
- 64
16
votes
2 answers
Jest & TypeScript: VS Code can't find names
I am using Jest with TypeScript. Despite the fact that my code works and I can build my project, Visual Studio Code throws me that error for all Jest methods (describe(), test()...):
Cannot find name 'describe'. Do you need to install type…

Alpha60
- 411
- 5
- 11
16
votes
4 answers
How to test HttpService.Post calls using jest
I am calling a API in nestjs service like below,
import { HttpService, Post } from '@nestjs/common';
export class MyService {
constructor(private httpClient: HttpService) {}
public myMethod(input: any) {
return this.httpClient
…

Devrath N D
- 601
- 2
- 8
- 19
15
votes
1 answer
I'm getting the error "_genMapping.maybeAddMapping is not a function" when I try to collect coverage from jest tests
I was able to run my tests and collect it's coverage just fine a couple days ago. But when I tried to run it today I got the error (0 , _genMapping.maybeAddMapping) is not a function for every test. The error only happens when I run with coverage…

Gustavo Cesário
- 1,310
- 1
- 12
- 23
15
votes
5 answers
Cannot find module '@babel/runtime/helpers/interopRequireDefault' from 'node_modules/react-native/jest/setup.js' when I run tests
I'm trying to build a mobile application with typescript, react-native, expo and jest. When I'm trying to run tests:
FAIL src/components/Button/tests/Button.test.tsx
● Test suite failed to run
Cannot find module…

Snyp
- 161
- 1
- 1
- 6
15
votes
2 answers
In Jest, how do I mock a Promise of void?
I'm using Jest and Typescript. I have a async function that returns nothing (void). How do I mock returning void? I tried the below
const myMockFn = jest.fn().mockImplementationOnce(() => Promise.resolve(void));
jest.mock('../config', () => ({
…

Dave
- 15,639
- 133
- 442
- 830
15
votes
3 answers
Jest passing tests but --covering option not picking up files
Problem description:
I have written two tests for a typescript class. Those two tests pass so jest successfully retrieves the test files. I then use the --coverage option but it appears jest is not picking the covered files here.
Here is the output…

Jaro
- 1,587
- 5
- 20
- 39
14
votes
3 answers
TS-Jest utils missing
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:
But in a newer project using ts-jest 28.x.x, when I try to import…

João Casarin
- 674
- 2
- 9
- 27
14
votes
1 answer
Jest/Typescript: Mock class dependencies in Jest and Typescript
I have class B which is dependent on class A. I want to test a method of class B which is internally calling a method of class A. Now, I want to unit test my method of class B by mocking class A.
My code structure:
class A {
getSomething() {
…

aniket singh
- 223
- 1
- 4
- 10