Questions tagged [jest-dom]
56 questions
2
votes
0 answers
Jest Unit test is failing for @microsoft/mgt-components even after adding the node_module to transformIgnorePatterns
I am using Microsoft authentication within my App to enable users to login. The flow itself is working seamlessly but the unit test is failing. I have added @microsoft to the transformIgnorePatterns property but seems like it is still not being…

hushie
- 417
- 10
- 23
2
votes
1 answer
Property 'toBeInTheDocument' does not exist on type 'Matchers'
Having problems setting up ts-jest with jest-dom and react-testing library in a Next JS app, it seems I am unable to get access to any of the @testing-library/jest-dom matchers.
Anyone have any insights about this sort of setup with typescript and…

Aaron Z
- 73
- 1
- 5
2
votes
0 answers
TypeError: element.getRootNode is not a function while testing
I am using react-testing-library with jest-dom. It is working fine but when i try to use toBeInTheDocument it throws the error TypeError: element.getRootNode is not a function.
expect(getByText('Not in dom')).not.toBeInTheDocument(); // It…

Shubham
- 497
- 10
- 23
2
votes
1 answer
Jest Unit test cant determine Vuetify components visibility
I have a Vue2 project with Vuetify, and i am using Jest for unit testing my code. I am starting out testing some sample code and i simple cannot get Jest to determine if a Vuetify v-alert component is visible or not. I have tried the built in Jest…

user616
- 783
- 4
- 18
- 44
1
vote
0 answers
Echarts problem with vitest and react-testing-libraries
I am using a combination of vitest as test runnert, js-dom as dom matcher and @testing-libraries to create react component unit test.
After change from jest to vitest, I start getting an error on every component that has Echarts included.
I open…

xzegga
- 3,051
- 3
- 25
- 45
1
vote
1 answer
React + Jest: test hangs forever whenever I try to access DOM properties (i.e.: toHaveStyle)
For the past few months my tests have been working perfectly. My package versions are fixed, not ranges, and we have not updated any dependency. However, since three days ago, the tests won't run at all. Jest just hangs in the [RUNS]…

Unapedra
- 2,043
- 4
- 25
- 42
1
vote
2 answers
Jest-dom TypeError: $toString is not a function , Typescript, React, Next.js
I've been trying to configure jest and @testing-library/jest-dom to work with my typescript/react/next.js website.
Every-time I run the test I run into this issue and Im not sure exactly what is causing it. I've been stuck on it for 3 days now and…

theodore
- 13
- 4
1
vote
1 answer
Reasons to use getBy* in conjunction with toBeInTheDocument
There are plenty of examples of getBy* or findBy* queries are used in conjunction with expect().toBeInTheDocument(). At the same time the Testing Library docs say that both of those type of queries throw errors when 0 elements match.
So there is a…

maximalism
- 71
- 1
- 4
1
vote
1 answer
Testing the return value from an useMemo with React/Jest
I have a component that converts a person's name to two initials with a useMemo.
I simply want to test the content to be "SB" when the name is Sjaak de Boer. But the useMemo (or if I simple convert it to a return function) is slow so the test…

Bravebox
- 33
- 6
1
vote
0 answers
Vue Testing Library - Error in beforeCreate hook: "TypeError: Cannot read properties of null (reading 'init')"
I am writing my very first tests using @testing-library/vue. I am using Vue 2.7 and the version for testing-library/vue is ^5.6.1. Here is the component:
Hello world
…
LiteralMetaphore
- 61
- 6
1
vote
1 answer
Testing-library: removing element with waitForElementToBeRemoved doesn't get jest coverage
Here's a Toast component that is displayed when a button is clicked and disappears after x seconds.
For testing waitFor is used to change showToast state to true when API call is successful, then waitForElementToBeRemoved is used to check if the…

user14223448
- 11
- 2
1
vote
0 answers
How do I test react-select value with react-testing-library?
I am using the latest react-select (https://react-select.com/home) and react-testing-library (https://testing-library.com/docs/react-testing-library/intro/) with jest-dom (https://github.com/testing-library/jest-dom).
I am able to interact with the…

Patrik Novák
- 21
- 1
- 2
1
vote
1 answer
Jest-dom how to check if component have styles by id
I'm trying to check if this ModalVideo component have some styles applied when opened (prop isOpen={true}), like so:
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';
import…

Toni Michel Caubet
- 19,333
- 56
- 202
- 378
1
vote
1 answer
toHaveValue returns null while the input's value is 0
I'm working on a test code for my React project. What I want to check is 'if the input type is number, it disallow the text insertion'. Below is the test code I wrote.
it("disallow a text input", () => {
const input =…

bindy
- 23
- 4
1
vote
0 answers
ReferenceError: expect is not defined in react app
I am developing a react app, suddenly after adding two tests I got an error that is,
ReferenceError: expect is not…

Anwar Hossain
- 201
- 1
- 4
- 16