Category "jestjs"

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

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