Questions tagged [jest-dom]

56 questions
1
vote
1 answer

Why can I use expect expect().toBeInTheDocument from "@testing-library/jest-dom" if I'm not importing it?

I create a React.js App with "create React App" and I'm learning to run tests. Why in the below code I can use expect().toBeInTheDocument if I am not importing @testing-library/jest-dom? import {render, screen} from "@testing-library/react"; import…
1
vote
0 answers

Testing visibility of React component with Tailwind CSS transforms using jest-dom

How can I test whether or not a React component is visible in the DOM when that component is hidden using a CSS transition with transform: scale(0)? jest-dom has a .toBeVisible() matcher, but this doesn't work because transform: scale(0) is not one…
Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
1
vote
0 answers

jest, jsdom and document object when importing a function

I have a function that produces side effect. I am simplifying it to log the content of a Node element to keep the focus in the issues. logFile.js function log() { console.log(document.querySelector('#mydiv').textContent) } export { log } Then I…
Peter
  • 2,004
  • 2
  • 24
  • 57
1
vote
1 answer

Using jest-dom in StencilJS tests throws error

I have a unit test in StencilJS in which I am using a jest matcher from jest-dom. When I run the test it throws an error: TypeError: Right-hand side of 'instanceof' is not an object at checkHtmlElement…
Ric
  • 405
  • 3
  • 12
1
vote
0 answers

Why does React Testing Library fire a submit handler when it should not? Is Jest DOM to blame?

I have a sandbox where I've recreated the issue I'm encountering in my codebase. I have a form with a required field, and a callback inside of the submit handler for the form. The actual component correctly does not fire the event handler if the…
Marc Gray
  • 11
  • 1
0
votes
0 answers

How to check the values of Material-UI select items using React-Testing-Library if those values are dates

I'm rendering a Material-UI with select prop; i.e. a list. The list is dynamically build up depending on some arguments. Each item looks something like this, where value is a unique date string: some…
0
votes
1 answer

the css file is not taken into account in the tests of my custom library

i want to test the Hover onto one off my element into my custom lib but there is an issues when testing if the hover correctly apply my choosen style it seems that my css file is not taken when using the custom lib it should get on hover this style…
0
votes
1 answer

"Unresolved function or method toHaveValue()" and "Argument types do not match parameters" warnings | WebStorm

I am writing tests for React component with @testing-library/react and vitest. Here is my code: It works fine, but for some reason I get these annoying warnings: When I rewrite code to this: then the test fails: This problem also occurs with…
0
votes
1 answer

How to use jest-dom as standalone in a webpage?

I want to use/run jest-dom matchers separately/standalone (not in a test, but in a webpage) like this: import matchers from '@testing-library/jest-dom/matchers' window.matchers = matches This is what jest-dom GitHub claims: The intention is to…
Luís Soares
  • 5,726
  • 4
  • 39
  • 66
0
votes
0 answers

Jest, RTL, jest-dom. Find link by href regardless it content

I have a text container with a few links. I want to test link presence with particular href, no matter what text within. How can I do it?
Lorem ipsum dolor sit
Artem Reva
  • 13
  • 4
0
votes
0 answers

React - Jest test failing - TestingLibraryElementError: Unable to find an element with the text

I've a jest test that is failing on addition of a new component to the page. The test is about showing of an error alert once error occurs. Code works in local environment but fails during commit. Error Text: TestingLibraryElementError: Unable to…
SJaka
  • 712
  • 13
  • 40
0
votes
0 answers

jest-dom toBeVisible throws: TypeError: element.getRootNode is not a function

We recently updated some of our project dependencies and one of them was jest-dom, we went from v5.11.0 to v5.16.4. As of v5.11.10 they introduced a new condition to the toBeVisible method so that the element had to be in the document, as part of…
Jake Aitchison
  • 1,079
  • 6
  • 20
0
votes
1 answer

How do I test an inner function that is been looped over with jest

How do you test an inner function that is been looped over in jest? Example I have: index.js const innerFunc = (type) => document.querySelector(`input[name="${type}"]`).value; const anotherInnerFunc = (type) =>…
Mohamed
  • 425
  • 4
  • 14
0
votes
1 answer

How can I use both jest-dom matchers and enzyme matchers in the same repo?

We have been using Enzyme for a long time to test our react components but have started the migration to React Testing Library step by step. When trying to use the toHaveValue matcher in a RTL test it failes since the enzyme matcher with the same…
Ola
  • 150
  • 1
  • 6
0
votes
1 answer

Can't test the input checkbox properly when the element is disabled using @testing-library/vue

I'm trying to create some tests for a checkbox component but looks like I can't make an assertion for an input[type="checkbox"] when is disabled. In the first two blocks I'm testing if the checkbox can be checked/uncheck if the element is disabled,…