Category "jestjs"

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

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