Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
0 answers
21 views

how to mock a third party library and assert its functions were called (or spyon) with jest?

I am working with ngrx and signalr, and writing a unit test for my ngrx effect responsible for building, starting and stopping the signalR hub. this is my effect: import {HubConnection, ...
Natalia Cáceres's user avatar
0 votes
0 answers
29 views

Adding "test" target config to existing NX libraries

I am working on an application that uses https://nx.dev/ and https://angular.dev/ and is configured with https://jestjs.io/ to run unit tests. I normally use this command to generate new Angular ...
Francesco Borzi's user avatar
-1 votes
0 answers
26 views

How to mock my util DynamoDB GetItemCommand implementation?

I've got code that uses GetItemCommand to get data from my DynamoDb instance, however I'm not entirely sure how I go about testing my function that uses it. I don't want to test the GetItemCommand ...
physicsboy's user avatar
  • 6,082
-2 votes
0 answers
28 views

What error is this: "Jest encountered an unexpected token"? It came from "isPortReachable" import of my code to be tested

Im trying to do Jest testing for all my domain/service/business logic of my web app. One of the import was isPortReachable, and Conf, but apparently every file with this import would fail the test ...
Wer Wer's user avatar
0 votes
0 answers
16 views

NestJS & Jest: The presence of jest.config.ts causes "strange behavior" during build

I have a Nestjs service inside my monorepo project with the following structure: / - package.json - packages/ - - frontend/ - - backend/ - - backend/package.json backend is the nestjs service, ...
Northern Bottlenose's user avatar
-1 votes
1 answer
34 views

What is "Argument of type <mock parameters> is not assignable to parameter of type 'never'" in Jest?

I took a bunch of examples online and ChatGPT code to do my testing. I ended up with some red squiggly lines under the parameters mockResolvedValue with the error: Argument of type '{ email: string; }'...
Wer Wer's user avatar
-1 votes
0 answers
22 views

How to properly unit test initialisation of pg-promise via jest.mock / jest.mocked methods?

Currently, I have setup my code as follows: import pgPromise from "pg-promise"; const pgp = pgPromise(); export const createDBConnection = async () => { const db = pgp({ ...
renkinjutsushi's user avatar
0 votes
0 answers
37 views

ts-jest unable to process a file

I am new to jest and am trying to implement unit tests in a sharepoint framework solution. I am using ts-jest to process my typescript files and am currently struggling to get a self built package to ...
Ludie's user avatar
  • 1
0 votes
0 answers
19 views

Jest has different behavior in watch mode

I'm writing a extension for chrome omnibox. And I'm using jest to write testing, but I found that the behavior of npx jest and npx jest --watchAll are different. Detailly, npx jest works fine and it ...
July Treee's user avatar
-1 votes
1 answer
31 views

How to mock optional methods as undefined in Jest?

I am writing unit tests for a NestJS/Express server that uses the express-session package. It has an object with methods that might not always be defined. In my code I check for it to exist first, ...
Chris Barr's user avatar
2 votes
0 answers
60 views

Is there a way to verify order of HTTP calls?

I am using the Nock library for mocking HTTP calls, with Jest as the testing framework. I am loading mock calls from a json file. Tests work fine, but I want to make sure certain calls happen before ...
Amir Rachum's user avatar
  • 78.7k
0 votes
0 answers
50 views

pg-mem with typeorm for in memory jest testing

i have a express app i am creating in typescript. I also am using typeorm as my orm for connecting to the database and actioning on it. I already have jest unit tests but i also wanted to create ...
Attiq Ahmed's user avatar
0 votes
1 answer
17 views

How to Mock TypeORM's Entity Manager Transaction for behavior assertion when Unit Testing in Jest?

Question I am trying to write a unit test for a method that uses TypeORM's entity manager transaction. The method is defined as follows: class MyRepository { private readonly repository: Repository&...
Sergio Yepes's user avatar
0 votes
0 answers
26 views

Using Jest to mock an AWS S3 call results in Argument of type 'any' is not assignable to parameter of type 'never'

I'm having an issue with a test that tries to mock a an S3 call with Jest. The module under test does something like this import { S3Client, CopyObjectCommand } from "@aws-sdk/client-s3"; ...
ddewaele's user avatar
  • 22.6k
0 votes
0 answers
35 views

How can I effectively isolate state in Jest?

I want to write my tests using GIVEN, WHEN, THEN. GIVEN sets the initial state (e.g. initializes instances), WHEN changes it (eg calls methods on those instances), THEN asserts the new state (e.g. ...
Amgelo563's user avatar

15 30 50 per page
1
2 3 4 5
238