22,936 questions
0
votes
0
answers
6
views
TypeError: Cannot read properties of null (reading 'getConfig')
how can i resolve this problem and this my jest.config.js
module.exports = {
preset: 'react-native',
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
]...
Tooling
0
votes
2
replies
47
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
54
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:
...
-1
votes
0
answers
44
views
Unit test for React/Chakra [closed]
This is my parent component.
import { useState } from 'react';
import VButton from 'ui-components/src/v2/VButton.jsx';
import { Provider } from 'ui-components/src/v2/providers/chakra.jsx';
import { ...
0
votes
1
answer
50
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
votes
0
answers
57
views
Argument of type 'PoolConnection' is not assignable to parameter of type 'never'
I want to mock transaction as PoolConnection
jest.mock('../../src/config/db.js', () => ({
__esModule: true,
default: {
execute: jest.fn(),
query: jest.fn(),
...
1
vote
0
answers
88
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
83
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
39
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
73
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
40
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-...
0
votes
0
answers
38
views
jest object in setupFilesAfterEnv differs from jest in test files
I’m trying to add a custom method onto the Jest API inside a setup file (config.ts) configured via setupFilesAfterEnv. However, the jest object I mutate in the setup file is NOT the same reference as ...
0
votes
0
answers
428
views
Mock jsdom Location using @jest/environment-jsdom-abstract
Jest 30 uses JSDOM 26, which breaks my tests. I want to test if location.search was modified.
Since JSDOM 21, it is not possible to mock location.search as easily as it used to be:
// does not work ...
0
votes
0
answers
85
views
Jest hangs when publishing to @google-cloud/pubsub in integration test
I have an integration test that publishes a domain event to Google Cloud Pub/Sub (using the Pub/Sub emulator). Eventduspatcher.integration.test.ts passes but Jest prints:
Jest did not exit one second ...
0
votes
0
answers
197
views
Failed to parse the TypeScript config file with Jest 30.x and Node 22.18+
I'm running into some inconsistent behavior with Jest 30.x, specifically when parsing a jest.config.ts file that imports another TypeScript module, on Node.js 22.18+. My code uses ESM syntax for the ...
1
vote
0
answers
46
views
Is Jest cache shared with other projects on a CI server?
My question is related to Enabling Jest cache in CI servers but a bit more specific.
We use Jest with cache enabled on a CI server running tests on multiple projects.
By default, Jest uses /tmp/...
0
votes
0
answers
63
views
Unable to find element text from Backstage Table component in test (All components (2) not found)
I'm testing a Backstage plugin component that renders a list of Ansible components using the Backstage Table from @backstage/core-components.
In my test, I mock the catalog API to return 2 entities (...
1
vote
1
answer
55
views
How to mock an imported hashPassword function in Jest when testing a registerUser method?
Question
I have a registerUser method that imports a hashPassword function from a local utility module.
// registerUser.ts
import { User } from "../models/user.model";
import { hashPassword }...
0
votes
2
answers
125
views
Nextjs with Jest - unexpected token export
I have a Next.js project with TypeScript.
It's a page router instead of an app router
No babel config file(.babelrc etc) in the project
The error occurs when I run npm test. jost seems to be one of ...
0
votes
0
answers
58
views
Jest coverage shows different results when running single test file vs all tests
I'm experiencing frustrating Jest coverage inconsistencies in my React project. When I run tests for individual files in isolation, I get perfect 100% coverage as expected. However, when I run the ...
0
votes
1
answer
73
views
Selector excluding nested values
nodejs: 24.7
jsdom: 26.1.0
Basically, I want to create a selector, that would exclude nested elements - it should find only elements at the first level of nesting. I have this:
it('Test selector non-...
3
votes
0
answers
76
views
Jest with TypeScript weird import error: SyntaxError: Cannot use import statement outside a module
Im trying to configure an unit test for my website with Jest and I can't get it to work correctly. I've tried some of the solutions suggested by the ts-jest documentation but it still hasn't worked. ...
0
votes
1
answer
80
views
testing an useState change inside a callback
I have a component like this to test:
import {doSomethingMocked} form 'mockedLibrary';
const TheComponent = (props) => {
const [isToTest, setIsToTest] = useState(false);
const handleClick = ...
-3
votes
1
answer
81
views
jest expect(1).toEqual(2) passes while it obviously should fail the test [closed]
Can you help me explain why this jest test case passes?
import { describe, it, expect } from '@jest/globals';
...
describe('jest assertions', () => {
it('2 should not equal 1', () => {
...
0
votes
1
answer
236
views
Mocked service throws NG0201: No provider found for `_HttpClient` error
I'm writing unit tests for NX libraries and one service is driving me crazy. It injects generated services and calls their exposed methods.
I'm using Jest + Spectator combination and I'm getting this ...
1
vote
1
answer
51
views
Combine toMatchSnapshot and toBeCloseTo behavior?
In my snapshot, I have objects of the following format:
{
"meanElements": {
"Om": 2.2835713400168607,
"am": 1.3043985097733939,
"em": 0.166565,
...
0
votes
1
answer
60
views
Jest/puppeteer test fails when importing helper function
I'm bumping into an issue importing a helper function, which calls Puppeteer methods, into a test file. I've created a simplified example of my problem.
I have a test in a file called my-test.test.js:
...
0
votes
0
answers
76
views
Testing functions that use the SVG API
I am beginning to add tests to my TypeScript web application using Jest. Some functions (or methods) use the SVG API and interact with the DOM. I installed:
jest
@types/jest
jest-environment-jsdom, ...
-1
votes
1
answer
86
views
Jest30+JSDOM30+Node24 TextEncoder is not defined [closed]
I'm aware of previous related problems with node12- & jsdom & textEncoder
but now, trying to create a jest30+jsdom30 config file doing as little as:
module.exports = {
testEnvironment: '...
0
votes
0
answers
47
views
Firebase/auth mock with JEST is not recognised
Im trying to test an error state which get updated when no foundEnterprise match is found:
async function onSubmit (data) {
try {
const enterprisesData = await fetchData()
const ...
0
votes
0
answers
35
views
NX E2E testing not generating coverage
Our project structure looks like this:
apps
|
---api
---api-e2e
with the e2e using @nx/jest for testing.
I'm trying to generate the coverage for API, but haven't been able to do it successfully.
I ...
2
votes
1
answer
428
views
Angular 20 : Locales extension changed .mjs -> .js. Transpilation problem with Jest
Angular 19 : Extension of locales is .mjs in @angular/common/locales.
Angular 20 : Extension of locales is .js in @angular/common/locales.
Jest's default configuration ignores transformation of ...
0
votes
0
answers
67
views
CSS file causing Jest/Puppeteer test to time out
The test below is a contrived example intended to demonstrate the issue I'm encountering. I'm using Jest and Puppeteer to test a function called doSomething. The file containing the function (random....
0
votes
1
answer
69
views
Jest test timeout with Express app and MongoDB Memory Server - "Cannot log after tests are done"
I'm experiencing a persistent timeout issue with my Jest tests for an Express.js application using MongoDB Memory Server. The test appears to be successful (receiving a 200 status code) but Jest times ...
-1
votes
2
answers
68
views
Testing for a particular date works locally, but not on GitHub
The task is to check if a certain date is a statutory holiday, by comparing a date against a list of known statutory holiday dates.
Here is the JSON list of stat holidays:
{
"provinces": ...
0
votes
0
answers
24
views
NestJS Guard jest test runs and succeeds but file is not included in coverage
I have a guard factory that returns a new guard Type to be used with NestJS @UseGuard decorator.
export function ParamValidationGuardFactory(opts: ParamValidationGuardOpts): Type<CanActivate> {
...
0
votes
1
answer
44
views
How to call onclick events written on div through jest (salesforce)?
I have created an LWC in Salesforce and am trying to creat Jest tests for it. I have implemented a div in html file and calling the js function using the onclick event as shown below.
<div class=&...
-1
votes
2
answers
69
views
How can I mock a single class in a module while preserving its structure using Jest?
I have a module (called myModule) which exports two classes (MyClass1 and MyClass2). I'm trying to mock a single class (MyClass1) from myModule using Jest, but I want the mock to preserve the ...
0
votes
1
answer
333
views
Turbo Native Modules - TEST - Jest - Invariant Violation: TurboModuleRegistry.getEnforcing(...)
This is my spec folder, on Android everything is ok too, everything works normally. Then I use NativeModule normally on a page, but Jest keeps failing.
import type { TurboModule } from "react-...
1
vote
2
answers
113
views
Unexpected result when unit testing router.navigate's toHaveBeenCalledWith method
Angular: 18.2.13
Jest: 29.7.0
I'm unit testing a method in my component which performs a router.navigate after a successful HTTP call. Note that I've removed some of the unncessary code for brevity
...
-1
votes
2
answers
582
views
Next.js and Jest: TypeError `the "original" argument must be of type function`
I am new to Next.js but not to React and Jest; this is the first test suite I'm setting up in Next.js.
I have the following (extremely minimal, but this example does cause the error) component I am ...
0
votes
0
answers
189
views
Jest setup with React native cannot use import statement outside of a module
Repo
I am trying to setup Jest in my Turborepo monorepo specifically in my UI package. I'm trying to setup Jest so I have a very basic test to see how it works:
Button.spec.tsx
import {describe, it, ...
1
vote
2
answers
124
views
Changing Angular ActivatedRoute values on a per unit test basis
I've got an Angular test suite which uses a MockActivatedRoute class I created. All of the values are null except when I need to set them for a given test. In general it works great, but now I'm in a ...
0
votes
0
answers
48
views
Using aws-amplify in jest test is unusable slow
I use the aws-amplify library to fetch oauth tokens. In productive code a signIn takes less than 1 second. When executing the same functionality in jest (v29), the sign in takes around 6 seconds which ...
0
votes
0
answers
51
views
Vue 3 + Jest: Function doesn’t trigger expected state change in test
I'm writing unit tests for a Vue 3 component using the Composition API, Vue Test Utils, and Jest. The component has a method that triggers an API call and updates a step variable based on the result. ...
2
votes
0
answers
57
views
How to test an Expo _layout.tsx component that uses useFonts and custom hooks? [closed]
I'm new to Expo and testing in general and want to write tests for _layout.tsx which looks as the following (actually it is just the default from the project setup with removed not-needed parts):
...
0
votes
1
answer
199
views
How to fix "React is not defined" in Jest tests for a TypeScript React project?
I'm writing Jest tests for a React project that uses TypeScript. When I run the tests, I get the following
error:
ReferenceError: React is not defined
I was able to get rid of this error by adding:
...
2
votes
1
answer
114
views
Jest tests stopped working after upgrading to React 18 (TSDX project)
I'm working on a React component library that was bootstrapped initially with TSDX (v0.14.1). After upgrading React from 17 to 18 and Storybook from 6.5.16 to 7.6.20, all my Jest tests stopped working ...
0
votes
1
answer
111
views
Fix error when running jest with react native- "invariant violation: native animated module is not available"
While running jest on a react native project I got this error:
"invariant violation: native animated module is not available"
0
votes
0
answers
44
views
How to mock services that are used in ESLint rule?
I have implement a custom ESLint rule such that when we import packages from another package using absolute path e.g.
import {something} from ../../libs/package2/subpackage
in package1 then ESLint ...