Category "jestjs"

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

Why is my resetAllMocks not working in jest

The second expect(fs.writeFile).toHaveBeenCalledTimes(1) (in describe('Guid for MPX') returns an error because the writeFile has been called twice. In theory, j

how to spy on window.location functions?

i need to cover my code with some unit tests and in one of then i have the following situation. app.tsx async someMethod( . . . windo

Javascript Jest MockImplementation : mocking values in a called function

I'm trying to test my backend's methods (to check users quota, like if they can use the app) and I have some trouble with a specific one. Indeed I have a functi

React-scripts test: no traceback on exception

I remake browser version of TacticToy game with React, and during unit-tests writing I've got a problem: there is no full traceback of a custom exception, only

Jest test a function integrated with the ssh2-sftp-client library

I need to test a function that write a file from local path to remote path on an sftp machine using shh2-sftp-client library. my own function is the following:

Mocking jQuery $() and $ functions in jest

I have a set of tests for the functions in an ES6 class that use $.get(). I was able to mock $.get(). I'm working on testing another function in the same class

How to test api is triggered or not in jest with testing react library

Login.js import {useSelector, useDispatch } from 'react-redux'; import Header from './Header'; import {submitForm, handleChange} from '../actions/authenticati

Async tests fail due to timeout

We are using jest 27 for our project in Angular 12 for running our unit tests. Locally, these tests run correctly but runnig them in a cloud agent pipe they bre

mount is not working in enzyam in react js

//write the test case got this error when i am using shallow its working fine but not gent expect value do you have any solutin please help to me import React f

TimeoutError: Timeout exceeded while waiting for event after click on button in autotest

Registration on the site consists of three stages. The first step is to provide a name, email address. When you submit the form of the first step, you are redir