Category "jestjs"

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

Jest testing multiple test file port 3000 already in use

I'm creating a testing for my express app. The project has multiple test files. In each module the server instance is required at beforeEach() method and closed

How can I get the arguments called in jest mock function?

How can I get the arguments called in jest mock function? I want to inspect the object that is passed as argument.

What are assertions in JEST?

It's documentation says that while dealing with async code, expect.assertions(x) should be written. What exactly do assertions refer to? Is it a term of plain J

React - Jest - Enzyme: How to mock ref properties

I'm writing test for a component with ref. I'd like to mock the ref element and change some properties but have no idea how to. Any suggestions? // MyComp.jsx

Typescript paths not resolving when running jest?

Attempting to convert this project over to jest using these instructions. I have everything working except for the files that use the paths configuration: "pa

How to mock interface with Jest without creating an instance

I know we can do it in Kotlin but I did not find it with Jest. I have complex interfaces and array of those interfaces and I do not want to specify all values o

How to view Jest snapshot in test

Is there a way to check the actual snapshot taken by Jest when running a snapshot test? So if I have a component with a fancy date thing that's supposed to show

Jest SecurityError: localStorage is not available for opaque origins

When I want to run my project with the command npm run test, I get the error below. What is causing this? FAIL ● Test suite failed to run SecurityError:

how to implement page navigation in react testing library (Link, a tag, history.push)

I am trying perform Dom testing at '/test' url page. my application use BrowseRouter from react-router-dom As following user approach, I want to manually chang

Jest gives an error: "SyntaxError: Unexpected token export"

I'm using Jest to test my React app. Recently, I added DeckGL to my app. My tests fail with this error: Test suite failed to run /my_project/node_modules/de

Jest beforeAll vs beforeEach unexpected behaviour

I have a quite simple test, basically I'm trying to mock i18next's t function: import { t } from 'i18next'; import { changeDocumentTitle } from './utils'; jest

Test process.env with Jest

I have an application that depends on environmental variables like: const APP_PORT = process.env.APP_PORT || 8080; And I would like to test that for example: A

What is jest's equivalent of `mocha -g` (grep option)?

Per the Mocha documentation, I can run a group of tests with a particular pattern in their describe/suite or it/test block using mocha -g. For example mocha -g

Babel throwing Support for the experimental syntax 'jsx' isn't currently enabled

I started newly writing unit test cases using Jest and Enzyme for the react application and when try to run test cases using jest like "test": "jest --watch" ra

Intercept navigation change with jest.js (or how to override and restore location.href)

Application code is calling location.href = "some-url". I want to write a test that verify the navigation redirect has happened. Using jest on jsdom, I tried t

TypeError: Cannot read properties of undefined (reading 'click'). fireEvent.click works but userEvent.click does not. Why?

Just started learning React testing with Jest, and am struggling with something simple. When I call userEvent.click(btn), the test fails saying that userEvent.c