Skip to main content
Filter by
Sorted by
Tagged with
103 votes
4 answers
131k views

I have this simple test: import React from 'react' import { render } from '@testing-library/react' import Button from '.' describe('Button', () => { it('renders button without crashing', () =&...
92 votes
18 answers
108k views

I am trying to test the onChange event of a Select component using react-testing-library. I grab the element using getByTestId which works great, then set the value of the element and then call ...
3 votes
2 answers
10k views

I am testing my React app and when it runs a test that executes the Web Cryptography API, specifically await crypto.subtle.generateKey I get the following error message ReferenceError: crypto is not ...
1 vote
2 answers
2k views

The React Testing Library docs specify that userEvent is to be preferred to fireEvent. However, I can't figure out a userEvent way to click to a particular value on a slider. With fireEvent, we can do:...
89 votes
4 answers
107k views

I'd like to test mouse interaction with an element using React Testing Library. Presently it's a bit unclear to me the difference between userEvent.click(element) and fireEvent.click(element). Are ...
4 votes
1 answer
10k views

I have an input with a dynamically-generated name that I would like to select with react-testing-library. RTL doesn't detect the input, even though the CLI error output contains an element with the ...
0 votes
1 answer
76 views

I have a component like this to test: import {doSomethingMocked} form 'mockedLibrary'; const TheComponent = (props) => { const [isToTest, setIsToTest] = useState(false); const handleClick = ...
4 votes
2 answers
21k views

I'm trying to test my UsersTable page in React, but the testing library gets the elements before they have time to render. Please check my code below: UsersTable.js import React, { useState, useEffect ...
21 votes
2 answers
25k views

I'm trying to run the below testcase using RTL , and the test is failing with the error "TypeError: Expected container to be an Element, a Document or a DocumentFragment but got string.". I ...
0 votes
1 answer
11k views

I have the following component: import { useState } from 'react'; export function MyComponent() { const [val, setVal] = useState(false); return ( <div> big container <...
0 votes
1 answer
2k views

I am struggled with writing tests to my simple form: import { useFormik } from 'formik'; import * as yup from 'yup'; import Button from '@mui/material/Button'; import TextField from '@mui/material/...
2 votes
3 answers
4k views

I need to override default testID attribute in React Testing Library. Using Jest as a testing framework. For this, I have followed the steps given here at individual test file level. Is there any way ...
6 votes
4 answers
10k views

I'm using tRPC with Typescript and Next.js. My tests used to not fail until recently (I don't think I touched them). I get the error Unexpected token 'export'. I've tried changing my jest.config.mjs ...
0 votes
1 answer
32 views

I'm wondering if it's better to use findBy together with rejects.toThrow instead of using queryBy with not.toBeInTheDocument when checking that an element is not displayed in cases like the following. ...
1 vote
1 answer
74 views

Earlier I was using NextJS 12 version & we stop generating the dynamic CSS class while writing the snapshot in React Testing Library by using the below method: mocks\styled-jsx\css.js function css(...
13 votes
2 answers
19k views

In a project we recently started using userEvent instead of fireEvent but now we are getting this issue FAIL src/modules/DashboardHeader/index.test.tsx            ● Test suite failed to run          ...
0 votes
1 answer
182 views

I have the following hook: function useWelcomeMessage() { const { data, error} = useGetWelcomeMessage(); const printMessage = useCallback(async () => { if (data) { alert(data) ...
1 vote
3 answers
8k views

I've recently begun utilizing React / DOM Testing Library in order to test all of my front-end React code. One of the first issues I've encountered is that with the way our application is laid out, I ...
1 vote
0 answers
87 views

I know that this is a well trodden topic, but most of the articles and help topics on this talk about how to avoid, and don't actually detail what exactly causes it. I have a simple example of how we ...
14 votes
3 answers
3k views

React Testing Library does not apply sx props of Material UI components during rendering. For example, I specify properties to hide an element at certain breakpoints. <> <AppBar data-...
43 votes
9 answers
58k views

Description: I am trying to test that a form submits when the user presses the "Enter" key. I have a passing test for when pressing the Submit button, but I also want to be sure the form submits with ...
2 votes
2 answers
2k views

The new Material UI DatePicker has a renderInput prop that gets a function that renders a text field. Works well enough, except that this function is rendered twice, and on first render it only ...
72 votes
13 answers
63k views

I am using Material UI autocomplete component and am trying to test it using react-testing-library Component: /* eslint-disable no-use-before-define */ import TextField from '@material-ui/core/...
24 votes
4 answers
13k views

I am using react-testing-library. In the document it says Note that using this as an escape hatch to query by class or id is a bad practice because users can't see or identify these attributes. ...
0 votes
1 answer
193 views

I'm building a NextJS (react) app with Chakra UI (version 3). I'd like to write unit tests, but I don't know to handle the way Chakra UI v3 handles select. Here's a sample test app: 'use client'; ...

1
2 3 4 5
75