22,915 questions
0
votes
0
answers
22
views
How to mock setTimeOut in a Jest unit test?
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 ...
0
votes
0
answers
22
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 ...
0
votes
0
answers
63
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
28
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 ...
1
vote
0
answers
28
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 ...
-1
votes
0
answers
54
views
Jest fails with "Module ts-jest not found" and "jest.setup.ts not found" despite npm install (Windows/Monorepo?) [closed]
I am trying to run tests in a project that seems to be structured as a monorepo (folder project-folder containing backend and frontend folders), but I am facing persistent path/module resolution ...
0
votes
0
answers
90
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
60
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 ...
1
vote
1
answer
61
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:
...
0
votes
1
answer
60
views
When upgrading to React 19 and NextJS 15, jest snapshots that had header changes via `next/head` break
In our tests, we had several snapshots that included content wrapped in next/head. We had previously followed the below pattern for the mock, which allowed us to see all the header tags like meta, ...
1
vote
0
answers
89
views
Problem with toHaveBeenCalledWith called from window object
This is my unit test:
import '@testing-library/jest-dom/extend-expect';
import {
render,
cleanup,
fireEvent,
waitFor,
waitForElementToBeRemoved,
screen,
} from '@testing-library/svelte';
...
1
vote
1
answer
91
views
Zustand persist doesn't execute in testing
I am doing unit testing for my project.
This is the code I want to test:
import { create } from "zustand";
import { persist } from "zustand/middleware";
interface LanguageState {
...
0
votes
1
answer
44
views
Why is jest `globalSetup` not run for certain project-related invocations? [closed]
I have a TypeScript monorepo that uses jest, and has a globalSetup script configured at the root config (it starts a local database process that many of the tests use).
Example
Directory structure
...
0
votes
1
answer
74
views
Element type is invalid on render method of "App" using Jest
I am attempting to run a simple Jest test to render the App element. This is our App.test.tsx:
test('render application', () => {
render(<App />);
}
This is the error that is being ...
0
votes
0
answers
42
views
Jest/Puppeteer test for a Chrome Extension fails with timeout on Firestore getDoc, but manual tests and Cloud Function succeed
I am building a Manifest V3 Chrome Extension using Firebase and testing it with Jest and Puppeteer. My manual testing works perfectly, but one specific automated test consistently fails with a 30-...