Category "jestjs"

Jest + Material-UI : Correctly mocking useMediaQuery

I'm using Material-UI's useMediaQuery() function in one of my components to determine the size prop to use for a <Button> within the component. I'm tryin

What is the difference between 'toBe' and 'toEqual' in Jest?

Jest documentation reads: toBe just checks that a value is what you expect. It uses === to check strict equality. And for toEqual: Use .toEqual when

Testing axios.create() instance with jest

I tried many solution from this task. I want testing axios instance api call without any libralies (jest-axios-mock, moaxios, msw, etc). I hope it's possible, b

Testing a Next.js app with a custom /pages/_app.js in React-Testing-Library

I'm attempting to follow this guide in Reat-Testing-Library documentation to wrap all the components I want to test. I'm doing this because I need access to the

Mocking moment() and moment().format using jest

I'm unable to mock moment() or moment().format functions. I have states where, currentDateMoment and currentDateFormatted are getting set as below. currentDateM

Mocking moment() and moment().format using jest

I'm unable to mock moment() or moment().format functions. I have states where, currentDateMoment and currentDateFormatted are getting set as below. currentDateM

Jest: Better way to disable console inside unit tests

I wonder if there is a better way to disable console errors inside a specific Jest test (i.e., restore the original console before/after each test). Here is my

jest.config is being ignored

I have the following in my jest.config.js module.exports = { preset: 'ts-jest/presets/js-with-ts', testEnvironment: 'jsdom' }; but it's being ignored w

Jest import statement: 'TypeError: Cannot set property 'fillStyle' of null'

I type: npm test and I get: It's interesting to note that the import statement works inside the BootScene.test.js file but it doesn't work in the imported fil

How to use Jest global Setup and Teardown in a nodeJS project?

I added tests to my node js project using jest but for each test suite there's a beforeAll method that creates a new test server and connects to a mongo databas

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 [email protected] 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