Category "jestjs"

Error running tests - jest.mock is not a function

I am trying to run tests using Jest, however I am getting this error: jest.mock is not a function What am I doing wrong? Here's my CodeSandbox: https://co

Eslint jest/globals environment key unknown

I have a custom eslint-config that has several plugins for various packages, including jest. I have the main set to an index which just extends other files. Lo

Typescript Build Fails When Adding Angular into Monorepo (Clashing of Jasmine and Jest Types)

Gist I have a Monorepo with solely Typescript packages. When I run tsc --build all packages will be compiled to Javascript. This worked fine until I added a pa

VSCode: How to debug current Jest test file

How to launch jest in debug mode on the current opened file, and only this one, regardless of the OS (windows, linux, mac). The problem: When using vscode und

Intellisense for Jest not working in VS code

Edit: Run npm install @types/jest To fix Just trying to type it() and the auto suggestion is isTag I've tried adding a jsconfig.json { "compilerOptions": {

Whats the difference between toBeInTheDocument and getBy* in @testing-library/react

Is there a difference between expect(screen.queryByText('<something>')).toBeInTheDocument(); And screen.getByText('<something>'); (The specific ge

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