Category "jestjs"

Setting Bearer Token in the header section while testing with Supertest

I'm trying to add the Bearer in the header section in POST request while testing with Supertest. I tried many methods. I'm a beginner in testing. Please suggest

Uncaught TypeError: Cannot read properties of undefined (reading 'isBatchingLegacy')

I am trying to test a react typescript project using jest but it's giving a confusing error: Error image Here is my package.json: "dependencies": { "@testin

How can I share snapshots between Jest tests?

Using TDD I'd like to write some new tests that create data in slightly different ways, and verify that that test data gets sanitized down to the same data as a

Jest test case for React hook component

When I write a react hook component which import '*.png' resource like this: import React, { useState, useEffect } from 'react'; import './topMenu.less'; im

text() method not available in Blob

I am doing some Integration tests with jest & nock to test Axios interceptors chaining. In one of them, I am expecting to receive a Blob instance and accord

Jest: TypeError: replaceAll is not a function

String.prototype.replaceAll() is a useful method and while building and executing everything works fine. However, all Jest-tests fail with the following error:

Can't receive valid test on specific test controller

I'm testing a sign-in controller and therefore I've written the following test: it("return 200 when user signed in successfully", async () => { await req

Jest (unable to set unique href for window.parent.location.href)

I have in my code a check to see if a page is being loaded inside iframe. App.js if (window.location !== window.parent.location) { console.log('App is running

Cannot find memory leak in my Express.js Jest tests

I've now spent some time trying to find memory leaks in my Jest tests, and even though I've successfully tackled some, there's still quite a lot of memory being

How to test NestJs response interceptor

I tried to follow this thread but it I keep getting an error. transform-response.interceptor.ts: import { Injectable, NestInterceptor, ExecutionContext, CallHan

userEvent in React Testing Library Doesn't Cause onClick To Be Called

I'm trying to run a really simple test with react-testing-library where a button is given a mock function, the button is clicked, and the test checks that the f

component props not getting called on test cases

TypeError: Cannot read property 'setState' of null 251 | useStateSpy.mockImplementation((init) => [init, setState]); 252 | const component = shal

How to strongly type jest mocks

I would like to strongly type my jest mocks. To a certain extent, I can make it work but when a class has private properties I'm stuck. An additional question,

How to mock VueAxios in jest

I want to test my Api functions which are on separate file outside vue component. Inside this methods i call api by Vue.axios, and i can't find the way to mock

Render() Modal test Jest Enzyme

I am not really how to test render() Modal. I am able to set up the props and test Render () " make sure it render with all the props" correctly " without any p

toHaveStyles not working with module.css styles using React testing library with Jest

I have this component for which I am writing test case using react testing library I am facing an issue with styles when the styles is imported from .module.cs

Jest SpyOn choose the correct overload

I do have a class that has 2 overloaded methods. public static create<M extends Model>( this: ModelStatic<M>, values?: M['_creationAttribu

How to test if React component is returning null or its children using React Testing Library?

I have a React component that returns its children to be rendered by React if the prop isTrue is truth-y. If its prop isTrue is false-y, then the component retu

Two empty strings are not equal in Javascript error

Before you dislike, leave a comment telling me why... One of these strings is imported using fs and the other is created through code. I noticed some weird char

How to see stacktrace / cause of an error in Jest?

I'm trying to debug a nodeJS app. I have some code which causes an error, a variable is undefined. When I run the code normally, the error is very clear and eas