Category "jestjs"

Jest: How to expect two arrays to be disjoint

I need to assert that an array does not contain any of the elements of a second array. In other words, I need to assert that two arrays are disjoint. I have tri

`regeneratorRuntime` is not defined when running Jest test

The title pretty much explains what I'm facing. I'm trying to test a React component that has some state, and I attempt to provide my store to the component in

How to test Custom Elements / Web Components with Testing-Library, Jest and JSDOM?

I am trying to test an Angular app with testing-library/angular@11 and jest@27.4.4 which uses custom-elements quite heavily. Unfortunately I am not quite sure i

Testing private method using spyOn and Jest

My functions in Calculator class is private and I can't test in this way, describe('calculate', function() { it('add', function() { let result = Calculat

Jest 27: How to reset mock for jest.spyOn(window, "setTimeout")?

I am updating a project from jest version 26 to jest version 27. As part of the update I had to switch from assertions on setTimeout to assertions on jest.spyOn

Jest: setSystemTime is not available when not using modern timers

Here is the code. I'm getting error TypeError: setSystemTime is not available when not using modern timers when I run the test. I have "@jest/fake-timers": "^27

Jest matcher to match any one of three values

I have this selector in my component whose default state is '' (empty) string but when change event is fired user can select any one of the three values that is

Jest not recognising JQuery Object ($)

I have used JavaScript to created a simple web application to measure how much time I spend on different projects. I want to test the code with Jest and this wo

Angular 12 setting up Unit test with JEST when running no tests found

Edit: My Jest was not setup on my Angular project properly. so if you are experience this then your Jest was not setup properly, if anyone has a good guide on s

How do I import ES6 Module within a create-react-app without causing tests to fail?

When I follow the instructions found here and add the import reference as they specify: import "@ui5/webcomponents/dist/Button"; the application works fine a

How can I unit test that a guard is applied on a controller in NestJS?

I've got a controller configured in NestJS and I want to check that the appropriate guards are set - does anyone have an example of how it could be done? This

How to test Material ui's DatePicker with Jest and Enzyme

i've got a problem. I'm trying to test material ui's datePicker (https://mui.com/api/date-picker/) with Jest and Enzyme. I've searched alot but couldnt find any

How to test an exception was not thrown with Jest?

The Jest docs do not demonstrate a way of asserting that no exception was thrown, only that one was. expect(() => ...error...).toThrow(error) How do I asse

Run Jest tests only for current folder

I have Jest installed on my machine and typing jest from terminal results in tests from parent folers also getting executed. I want to run tests only from the c

Mocking auto generated model functions created using sequelize-auto package

I have created my models using the sequelize-auto package and used them in my controllers const sequelize = require('../database/db'); var models = require("../

How to change mock implementation on a per single test basis [Jestjs]

I'd like to change the implementation of a mocked dependency on a per single test basis by extending the default mock's behaviour and reverting it back to the o

Spy on a function inside functional component using React testing library

I'm trying to spy on a function inside a function component using react testing library. I wanted to test whether handleClick function has been called whenever

How to test if a component is rendered with the right props when using react-testing-library?

I have some components that are rendering another component (FetchNextPageButton) that is already tested in isolation, like these ones: const News = () => (

How can I test swiper with Jest?

I'm creating unit testing of Swiper using Jest. Here is my code: https://codesandbox.io/s/swiper-default-react-forked-v0dnz?file=/src/App.test.jsx ● Test

How to define default mock data for relay?

I am doing unit tests on a react app that is using relay as a graphql client when testing , i get mocked data with like this : title: '<mock-value-f