Category "jestjs"

jest unit test and retry-axios node.js

I have been trying to use the retry-axios library and assert the number of times in a "get" has been called without any luck. Here is my setup: axios.config.ts

Can you write async tests that expect toThrow?

I'm writing an async test that expects the async function to throw like this: it("expects to have failed", async () => { let getBadResults = async () =>

Using jest's test.each vs. looping with forEach

Is there a reason I would prefer one method over the other? Here are some examples: describe('some tests', () => { [1, 2, 3].forEach(num => { test(

How to install typescript + jest with create-react-app?

I want to install typescript and jest in a create-react-app-based app. I feel that since this is such a common installation choice there must be at least one "e

Testing Svelte components with dynamically imported components in jest (await import)

I'm writing a test in jest for a svelte component which dynamically imports another component. The following snippet is the part where the dynamic import happen

Angular/Jest - Test that the subject has thrown error after setter is called

I have a class that is responsible for setting the theme for my application. I'm trying to test that it throws an error if you give it a theme that it does not

Mock Service Worker returns empty

I'm new to react testing library. I am trying to test a simple component that call some apis and then it fills inputs with the data of these apis. But when I ru

Mock Service Worker returns empty

I'm new to react testing library. I am trying to test a simple component that call some apis and then it fills inputs with the data of these apis. But when I ru

How to set up Jest w/ESM to recognize non-cjs modules in node_modules

Have got a successful jest/esm setup, however occasionally a module is released that specifies both a main key (for commonjs) and a module key (for ESM) in its

How to create nested moduleNameMapper in Jest?

My simplified jest.config.js is: module.exports = { preset: "ts-jest", collectCoverage: true, collectCoverageFrom: [ "src/**/*.ts", "!**/node_mod

How can I write a jest test if in a component uses a function that is passed through the context?

It is necessary to test the component SlotItem. In it function is transferred through a context this.context.i18n.t("free") My component: import React from 'r

TypeError: (0 , _axios.default) is not a function when use jest.mock('axios') inside a *.test.js file

I try to mock axios module inside my test file like this // mycomponent.test.js import axios from 'axios'; jest.mock('axios', () => ({ get: jest.fn(() =&

TypeError: (0 , _axios.default) is not a function when use jest.mock('axios') inside a *.test.js file

I try to mock axios module inside my test file like this // mycomponent.test.js import axios from 'axios'; jest.mock('axios', () => ({ get: jest.fn(() =&

How to test a required input field with React Testing Library and Jest?

I tried to test a required input field with React Testing Library and Jest by testing the existence of the popover, but I failed. I tried several variants and n

How to query by text string which contains html tags using React Testing Library?

Current Working Solution Using this html: <p data-testid="foo">Name: <strong>Bob</strong> <em>(special guest)</em></p> I

How to test for document being undefined with RTL?

I have the following react hook which brings focus to a given ref and on unmount returns the focus to the previously focused element. export default function u

How to test _document in Next using Jest

I'm trying to achieve 100% coverage in a project and this is the only file I can't test because I haven't got any idea of how to do it. I don't even know where

Jest: "Directory in the roots[0] option was not found"

I am trying to set up monorepo to run all of its Jest tests at once. In each package, I'm using react-app-rewired to get Babel to transpile code imported from o

Test suite failed to run import.meta.env.VITE_*

After adding the environment variable import.meta.env.VITE_* in my code, the tests with vue-test-utils started to fail, with the error: Jest suite failed to run

Disable Coverage on Untested Files - Jest

When using @vue/cli-plugin-unit-jest, I am receiving coverage reports each time I run my unit tests, regardless of whether I have the --coverage flag in the exe