Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
21 views

How can I mock up the express-validator withDefaults function using jest?

I am trying to unit test my validation segment which uses express-validator. This is the start of the segment: const errorMsgs = require('../lib/error-messages'); const validationResults = ...
Bragon's user avatar
  • 105
1 vote
0 answers
15 views

My jest test keeps failing and I can't understand why

This test is keeps failing with a zero call result from jest. I have no idea why this keeps happening like: Number of calls: 0Jest " " it("should log game data on console", async ...
kallmekye's user avatar
0 votes
1 answer
18 views

Mock being ignored, jest node

I'm trying mock a database with this test but the mock seems to be ignored. I can't think of a reason this could be? import { jest } from '@jest/globals'; jest.mock('../database', () => ({ ...
Ed Lynch's user avatar
  • 615
0 votes
0 answers
16 views

Jest testing "Cannot access 'mockDb' before initialization" [duplicate]

import { getDocument, saveDocument } from "./request"; import { getDocument, saveDocument } from "./request"; const mockDb = { get: jest.fn(), insert: jest.fn(), }; jest....
036謝金輝 Michael's user avatar
0 votes
0 answers
12 views

I have a question about testing code for infinite scrolling functionality using IntersectionObserver

I'm currently working on a React + TypeScript + React Query project, and I'm having trouble writing test code! The first piece of code is the MainGrid component, where I am using a custom hook called ...
cloudia's user avatar
0 votes
0 answers
24 views

Dependency (upstream) services are undefined with no useful error when doing e2e testing using Jest

This is in NestJs, using Jest. I am trying to test my controller, which relies on my "main" service. I wish to perform e2e testing on the controller. (To clarify, my smaller unit tests of ...
Raddaya's user avatar
  • 23
1 vote
0 answers
20 views

Angular - Unit test rxjs timer with default value

I have a component that uses rxjs to display a countdown timer. It has a default starting duration of 60 seconds, but can be overridden via input. I am trying to build a unit test that verifies: the ...
Cody Pritchard's user avatar
-1 votes
0 answers
32 views

Can't add custom matcher to expect because of TypeError

I'm having problems adding a custom matcher to Jest. This example from the Jest docs doesn't work in VS Code: import {expect} from '@jest/globals'; import type {MatcherFunction} from 'expect'; const ...
starkipraggy's user avatar
0 votes
0 answers
38 views

How to unit test a Web Worker file with Jest? [closed]

I'm trying to unit test a separate Web Worker file in isolation using Jest. The worker file looks like this: /* eslint-disable no-restricted-globals */ let inactivityTimer = null; function clearTimer(...
YI LU's user avatar
  • 21
0 votes
0 answers
34 views

error testing custom backstage plugins with jest

I am a new tester testing backstage components and I am having problems with jest when processing them because of the following issues: I'm testing with typescript and I'm trying to test external ...
Jean Carlos Ramirez's user avatar
0 votes
0 answers
34 views

Jest mocking core NodeJs module

I'm trying to write an abstraction layer for an Electron application that runs in a Node (v20) environment. This layer will make it so that there is only one access point to the file system for the ...
NoNamer777's user avatar
-1 votes
0 answers
13 views

and.stub() using in Jest

I am currently migrating my tests from Jasmine to Jest and I have the following question: Initial situation where .and.stub() is no longer available in Jest. it('should navigate on show car detail', ()...
Andreas's user avatar
  • 27
0 votes
0 answers
19 views

NextJs Jest module import alias not resolving properly

In my very basic unit test, Jest not resolving the import alias properly. app\page.tsx import { getRandomLocation } from "@/lib/services/util-service"; import styles from "./page.module....
Karthikeyan's user avatar
-1 votes
0 answers
9 views

Im trying to write unittest for a route handler using sinon and mocha and can't stub using mocha

my route handler is, I wanna write using mocha and sinon and possibly supertest but if your code works in jest please send that too router.post('/sign-up', async (req, res) => { try { const { ...
Mehdi_'s user avatar
  • 7
-1 votes
0 answers
21 views

TypeError: Cannot destructure property 'setUserId' [closed]

The Login Component logs in successfully and sets userId in context Now, the problem is Cannot destructure property 'setUserId' after I use npx jest path.. TypeError: Cannot destructure property '...
SleepyDev's user avatar
0 votes
1 answer
16 views

Jest with Firestore: ReferenceError: Cannot access 'object' before initialization

I'm having a problem with my jest test to mock my Firebase functions roleService.unit.test import { RoleService } from "../../services/RoleService"; import { CustomError } from "../../...
Eduardo's user avatar
  • 1,777
-2 votes
1 answer
43 views

jest not able to understand "export default" in a specific file

I have package called sinon js installed to my react app, I have version 5.0.10 of it which is deprecated. So I decided to upgrade it to latest version which is 18.0.0 This package is used in my test ...
مالك الدسوقي's user avatar
1 vote
2 answers
53 views

How to cover the catch block in a function with optional chaining using Jest in react?

I'm working on a React project where I have a function that uses optional chaining and a try-catch block to assign a navigate function. I'm trying to write a Jest test to cover the catch block, but I'...
max's user avatar
  • 303
0 votes
1 answer
18 views

Jest mock of a singleton function

I have a singleton class created in a module consumed within a class of an app, I am attempting to change the mock implementations return value of the singletons contained function, in the example ...
Deviland's user avatar
  • 3,364
-1 votes
0 answers
83 views

TypeError: Cannot read properties of undefined (reading 'keys')

While developing NextJS 14, I try to use Jest v29.7.0 for testing API and Frontend component. I follow instructions of NextJS site: Setting up Jest with Next.js (link) The error FAIL src/app/api/...
Dương Minh's user avatar
-1 votes
0 answers
25 views

TypeError: Cannot read properties of undefined (reading 'dynamicSheet')

I'm facing a TypeError: Cannot read properties of undefined (reading 'dynamicSheet') error while unit testing my scrollableComponent. I'm trying to mock the ref container's scrollWidth and clientWidth ...
Bimal Sunil's user avatar
0 votes
0 answers
27 views

@typescript-eslint/no-confusing-void-expression Error with TypeScript Function Returning undefined

I am encountering a linting error in my TypeScript code related to the @typescript-eslint/no-confusing-void-expression rule. My function, getNestedProperty, is designed to return either a value or ...
raghuveer ambedkar's user avatar
0 votes
0 answers
42 views

TypeError: _reactQuery.QueryClient is not a constructor, @tanstack/react-query migration to v5 in jest tests

I migrated my @tanstack/react-query package to version 5 and followed all the steps of the breaking changes in the doc, but now when I run the jest tests I get the following error: TypeError: ...
FabienChn's user avatar
  • 958
0 votes
0 answers
40 views

Jest reporting lines are uncovered when they actually are covered

I have a file reporting as only 48% covered, but when I looked at the report its very confusing because it seems like those lines are covered by tests. Example: Settings.js class Settings { general ...
Hershizer33's user avatar
  • 1,246
0 votes
2 answers
361 views

Facing issue while migrating Jest@26 to Jest@27

I'm trying to migrate Jest from version 26 to 27 in my Next.js 13 project but facing the following error while running test after updating to Jest 27 version - FAIL src/__tests__/app.test.tsx ● ...
Sagar Sharma's user avatar
3 votes
1 answer
80 views

Only update signal if other signal value actually changed

After getting the answer for how to test an update triggered for a signal (my question here , I have another situation around testing signals. I created a stackblitz project. in the old folder you can ...
Ruth's user avatar
  • 1,059
-3 votes
0 answers
26 views

how to jest for 'today' result? [closed]

export class CheckDateDto { getDay(): string { if (isTodayInTomorrowOut()) { return 'tody' } return 'monday' } } export function isTodayInTomorrowOut(): ...
arleigh sino's user avatar
1 vote
1 answer
90 views

How to test a signal with jest and Angular 18?

I am currently trying to migrate from rxjs behaviorObject to signals. We do have some tests that test the update of a signal. But when I try to migrate our jest tests to the new signals, I get ...
Ruth's user avatar
  • 1,059
0 votes
0 answers
40 views

Jest encountered an unexpected token. By default "node_modules" folder is ignored by transformers

Im Running a Test File and Getting the Following Error ● 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 ...
Mr.Yuu's user avatar
  • 15
-1 votes
0 answers
17 views

react latest version getting some error while running the test cases [closed]

Installed the latest version for react app trying to run the application it was working, but when i try to run the test cases with npm run test throwing below error [email protected] test > ...
Hussian Shaik's user avatar
1 vote
2 answers
56 views

Is there a tidy way to type narrow as a result of jest assertions?

An annoying issue I encounter when writing tests looks like this: function getData(): { isLoading: true } | { isLoading: false; data: string } { return { isLoading: false, data: "hello ...
dwjohnston's user avatar
  • 12.5k
1 vote
0 answers
38 views

Failure to mock global.fetch() function

// evaluator.ts export class Evaluator { private functionRegistry: FunctionRegistry; constructor(functionRegistry: FunctionRegistry) { this.functionRegistry = functionRegistry; } async ...
Mert Aydın's user avatar
-1 votes
0 answers
30 views

Testing Data Transfer Objects (DTOs)

I'm writing unit tests for a NestJS app using Jest and am wondering whether it's necessary or beneficial to create unit tests for DTOs (Data Transfer Objects). Are there any pros and cons to testing ...
Mariam Khaled's user avatar
-1 votes
0 answers
23 views

Jest Test of React Component Not Calling Mock Function

This is likely something easy that I'm just not seeing since I'm new to jest. I'm trying to write a unit test for the handleClickSetSelectedAnswer() method in my Answer React component. The ...
Denise's user avatar
  • 67
0 votes
1 answer
31 views

Issue with module imports and exports: (TypeError: featureCore is not a function)

I have a node project with the following format: structures/extendedClient.js utils/feature.js tests/feature.test.js In extendedClient.js I have the following: class extendedClient extends Client { ...
Iain Moar's user avatar
1 vote
0 answers
20 views

Mocking @react-navigation/stack GestureHandlerRefContext in Jest

I am using @react-navigation/stack and have Jest tests failing anywhere I am using the GestureHandlerRefContext in a component: TypeError: (0 , _native.createNavigatorFactory) is not a function >...
awsubtex's user avatar
-2 votes
0 answers
40 views

How to compare a moment Object using jest?

I am trying to test a function that returns a moment Object to see if it is returning the correct time, when I try to do something like this: const moment = require('moment'); const setsTime = (...
shoccho's user avatar
  • 41
-1 votes
0 answers
35 views

Getting error - exports is not defined in ES module scope

In my nodejs application, I don't have ES modules enabled. When I am adding dependency on p-queue library which has ES modules enabled. So I enabled ECMAScript in my application by adding "type&...
Gourav Aggarwal's user avatar
0 votes
0 answers
91 views

Jest encountered an unexpected token, In React app

I'm trying to run the test case for the app. But its showing below error. Can someone help me to clear the issue. Attaching the code repo. https://github.com/Arun12Muralidharan/team_tracker I can't ...
Arun Muralidharan's user avatar
0 votes
0 answers
17 views

Can not test shadcn input otp component with Jest

I'm creating an OTP page using Shadcn Input-OTP. Before importing input-otp component. All tests are running fine. But when it tries to run this component. it gives: ReferenceError: ResizeObserver is ...
Re9iNee's user avatar
  • 558
0 votes
1 answer
40 views

Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components)

This issue occurs when Jest fails to load SVG files. The error details are as follows: Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for ...
Blue A's user avatar
  • 333
0 votes
0 answers
41 views

Vitest unable to find element with role='button' and aria-label despite it appearing in the DOM debug

I'm encountering an issue with Vitest where it cannot find an element with role="button" and aria-label matching /open notifications/i, even though the element appears clearly in the debug ...
Tomás Benfica's user avatar
0 votes
0 answers
30 views

Testing MUI components that change with screen size

I have an MUI Drawer component that is given different props based on the size of the window -- above a certain window width, it becomes a permanent drawer and docks to the left side of the screen, ...
cdyswnnr's user avatar
0 votes
0 answers
34 views

Does this rollup script build a correct types.d.ts file, given that when the NPM package is imported it returns an error?

I'm trying to package a React component, written in Typescript, to release it open-source on NPM. This is the repo, which contains all files related to the project: https://github.com/lightenna/react-...
stanhope's user avatar
  • 306
0 votes
1 answer
26 views

Jest DynamoDB Test Failing

I am attempting to write a jest unit test involving using DynamoDB. It seems the afterAll condition is executing too fast which is making my integ test failing since it fails to get the already ...
mickychetta's user avatar
0 votes
0 answers
21 views

create-jest-runner throwing "cannot read properties of undefined" error

I am creating a custom runner for jest with create-jest-runner I am following the examples, but I keep receiving the error TypeError: Cannot read properties of undefined (reading 'startsWith') at ...
Jkaram's user avatar
  • 853
-1 votes
0 answers
23 views

Object not initialised in `describe`, but initialised in `it`

I'm coding a test with Jest and I have a long input at the bottom of my test file. When trying to access my input within an it function, the input is initialised, but not when trying to access it from ...
Supman's user avatar
  • 1
-1 votes
0 answers
35 views

Angular Jest to Vitest Migration

I am currently migrating an Nx Angular repo from Jest to Vitest as a proof of concept. I have altered all my tests to use Vitest imports e.g { describe, it, expect }. When I run my suite, I get 180 ...
cw23's user avatar
  • 65
0 votes
0 answers
10 views

Adding custom information in HTML report using "JEST_HTML_REPORTERS_CUSTOM_INFOS"

I am trying to include my additional information in the HTML report using JEST_HTML_REPORTERS_CUSTOM_INFOS variable. Here is my jest setup // jest.config.json { "preset": "ts-jest&...
lazy_coder's user avatar
0 votes
0 answers
22 views

jest javascript unit test issue. How to test class if class initialise is in the same file

I have something like that import {firstTableSettings} from "./firstTableSettings.js" import {secondTableSettings} from "./secondTableSettings.js" export default class ...
Eva's user avatar
  • 202

1
2 3 4 5
463