22,868 questions
Score of -2
-2
votes
1 answer
1
answer
51 views
51
views
How do you run a dummy useReducer dispatch function in Jest?
I'm currently trying to write unit tests for one of my components, but unfortunately it seems like the dummy dispatch function to take the place of the reducer's one is not firing at all. Up until ...
Score of 0
0
votes
0 answers
0
answers
84 views
84
views
How to prevent jest from adding a stack strace for every message printed to stdout
By default, if any script run by Jest output something to stdout, it will be displayed with a stack trace :
console.log
This is my debug message that I printed using console.log
at Query.#...
Score of -2
-2
votes
1 answer
1
answer
128 views
128
views
Unit tests fail with module not found error, but VS Code can find the pathing
I'm upgrading from Angular 20 to 21.
All of my unit tests are failing, with a mix of "Cannot find module" @angular/core/testing, @angular/common/http/testing, or @angular/common/http/testing....
Advice
1
vote
0
replies
76
views
React compiler and Jest tests
I added the React Compiler to my project (basic setup from docs), and my all Jest tests failed. Would it be better to disable the React Compiler for tests, or is there a way to fix this? How to do it? ...
Best practices
1
vote
2
replies
206
views
What are best practices for unit testing with Jest in JavaScript?
I'm learning Jest and want to make sure I'm building good habits from the start. I've read the official docs but they don't really cover what's considered good practice in real projects. Specifically ...
Score of 0
0
votes
0 answers
0
answers
77 views
77
views
Jest test suite fails with "import outside scope" from expo/src/winter/runtime.native.ts
Problem
When running Jest tests in my Expo 54 / React Native project, one test suite consistently fails with the following error:
The other tests in the suite run fine (16 passed, 4 failed all with ...
Score of 0
0
votes
0 answers
0
answers
68 views
68
views
How do you get node inspector to pick up source files and break on breakpoints?
I am using WSL. I am following the steps in the Jest Debugging Guide. I tried running this command:
node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand myTest
Then I open Google Chrome and ...
Score of 2
2
votes
1 answer
1
answer
91 views
91
views
How to mock setTimeout in a Jest unit test using FakeTimers?
In my application I need to ensure that an array of Promises will be executed in the order as given in the array. Addtionally, the application shall "wait" a certain time after each Promise ...
Score of 0
0
votes
0 answers
0
answers
42 views
42
views
SonarQube not picking up LCOV coverage in React frontend Maven multi-module build
I have a multi-module Maven project with a Java backend and a React frontend.
Backend Java coverage (JaCoCo) is reported correctly in SonarQube, but frontend JavaScript coverage is always 0%.
Project ...
Score of 0
0
votes
0 answers
0
answers
78 views
78
views
Typing a mocked module function with a different signature in Jest
I want to mock a specific module with a specific mocked function.
Later on, I want to supply the implementation in a specific test.
I have this code:
import fs from "fs";
jest.mock("fs&...
Best practices
0
votes
1
replies
60
views
How to avoid parallel Jest tests interfering with each other's databases?
If I run integration tests sequentially (Node.js, TypeScript) they are fine, but it can be really slow, but if I make them run in parallel they edit the same database and end up causing weird bugs. Is ...
Score of 1
1
vote
0 answers
0
answers
66 views
66
views
Jest mock not working in class singleton instance
I have created a class for connecting nats and assign it client property. application works as expected. But when I try mock the connection class for integration tests, then it does not work as ...
Score of 0
0
votes
0 answers
0
answers
113 views
113
views
How to run Next.js and Jest concurrently, with an instance of Next.js already running?
I have this script in my Next.js project, where I start a Next.js server (because the tests need it) and run Jest tests using concurrently:
"test": "npm run services:up &&
...
Tooling
0
votes
2
replies
74
views
How to write tests which analyze HTTP requests made on NextJS server side?
I work on a NextJS project with Pages Router. We are using Jest for unit tests and Playwright for E2E.
The application we are making is a funnel with several steps. Each step is a form with several ...
Score of 1
1
vote
1 answer
1
answer
80 views
80
views
Jest + Testcontainers MongoDB: Intermittent ECONNREFUSED errors running integration tests
Problem
Starting November 10th, my Jest integration tests began failing randomly with MongoDB connection errors. The tests use @testcontainers/mongodb v11.5.1 and mongodb v8.0.12.
Error:
...