Category "jestjs"

Exceeded timeout of 5000 ms for a test with Jest and MongoDB

I'm trying to implement database population by using a migration function. The code works perfectly, it saves all the data into the database, but the test for t

How to mock only one typescript class from a module, but leave other classes/functions as is, using the jest framework

I have a typescript module with a function that I'm trying to test with jest. The function I'm trying to test uses a typescript class that's defined in the same

I am trying to set a cookie in supertest but it does not work

I am trying to set a cookie session to a post request in supertest but I cannot. This is my test code: const app = express(); app.set("trust proxy", true); app

How to mock a 'request' node module for testing in jest

I am new to writing test cases in jest and i wanted to test 'mark' function and want to mock 'request' node module. let's say this file's name is app.js and tes

Why Jest tests are SOMETIMES failing on CircleCI?

I have Jest tests that are running against the dockerized Neo4j Database, and sometimes they fail on CircleCI. The error message for all 25+ of them is : thrown

Testing function that use useQuery @apollo/client with Jest

I am trying to unit test my function that call useQuery from @apollo/client. Here's what I have done getPixelID.ts import { useQuery } from '@apollo/client'; im

Testing call to other functions within the same component using nuxt.js and jest

I'm trying to write a test that tests the various method calls to other methods within the same file. So far, I've written tests for two different methods, one

how to mock slack web api for jest

i have an app that's using the @slack/web-api package through the named import WebClient. i want to test one of the controllers that uses a model that in turns

Jest: to check if a function is called by a specific instance of class in JavaScript/Typescript

I am testing some express middlewares with jest. it("should throw 400 error if request.body.id is null", () => { const req = { body: { id: null } } as an

What's the point of writing unit tests with mocks, if it cannot catch changes in the source code?

I started writing unit tests recently. When I try to test the service of the Angular component, I usually mock it. Therefore, if someone deletes the line of the

Jest + Supertest - API tests are using random ephemeral ports

I'm using Restify for my API and I'm trying to write tests for my endpoints. At first, I had only a test for ping and it was okay, but now, after I added a new

How to flush promises since Jest 26+

Jest 26 shipped a new implementation of fake timers based on @sinonjs/fake-timers. Previously I used const flushPromises = () => new Promise(setImmediate); a

Testing react component that uses Context - change state of component under test

I want to test the following React component import React, { useContext, useState } from "react"; import { IntlProvider } from "react-intl"; export const Conte

How to conditionally mock error responses with msw

The UI I'm working on is rendered differently based on the response received. I would like to test the UI when a 4xx and 5xx responses are received. My api hand

Test correct SVG component renders with jest and react-testing-library

I have an svg inside a React component that renders conditionally. <div className='avatar'> {gender === true ? <MaleAvatar /> : <FemaleAvat

React Testing Library Not Parsing JSON

I have a TextArea component that takes JSON {"someKey": "someValue"}. When I inspect the dom, {"someKey": "someValue"} shows up just fine in the inspector. Howe

Mocking federated modules in host application for jest

Question is exactly same here in fact but has different context: How to mock not installed npm package in jest? I am part of a project where new Module Federati

Jest Runner won't allow me to debug tests just skips test each time

skipped test When pressing debug on the test it just skips it. It works for other tests in different repositories that I have, but for this specific one it does

Jest won't accept top-level-awaits with NodeJS16 & TypeScript

I'm trying to update my NodeJS12 & TypeScript app to Node16, one if the reasons is the need to use top-level-awaits. The code compiles correctly after the u

_enzymeAdapterReact.default is not a constructor when test jest

I'm having this issue when test react-native component with jest and enzyme TypeError: _enzymeAdapterReact.default is not a constructor Here is my dev dependen