Skip to main content

Questions tagged [react-testing-library]

Questions about testing React components with the react-testing-library utility.

react-testing-library
0 votes
0 answers
15 views

How to change the value of a MUI DatePicker or TimePicker in Jest/react-testing-library?

I have a component that uses the Material UI datepicker and timepicker. function MyComponent() { const [dateFilter, setDateFilter] = useState(moment()); const [timeFilter, setTimeFilter] = ...
CodeMan's user avatar
0 votes
1 answer
27 views

How to get and test an element style using RTL?

I have a sidebar menu component, which has a small tab to be pressed in order to show/hide the menu. The tab, as the entire menu, can be rendered on the left or the right side of the screen based on '...
TjFSimoes's user avatar
0 votes
1 answer
42 views

renderHook not rendering items called from API

I have a custom hook (useFetch), which I'm using inside a page to pass data into a <Products/> component. export default function App() { const { products, totalProducts, currentPage, ...
Matheus Oliveira Damião's user avatar
1 vote
1 answer
26 views

Test function inside useEffect

I am testing my components using Jest and React Testing Library. The current code is updating a title in the TopBar component based on scroll position and current collection title: const [...
Kimimo's user avatar
  • 33
-1 votes
1 answer
32 views

React testing library with jest : trying to test the existence of a button with toHaveLength fails. Why?

I just started trying out react testing library with jest, going through a tutorial and have the following question: const App = () => { return ( <form onSubmit={handleSubmit}> &...
learningcoding's user avatar
-1 votes
0 answers
27 views

How to run multiple test cases from single directory using Jest

I have the following directory structure: parent dummy runas src __tests__ packages runas src __tests__ jest.config.js package.json I want to run all ...
Vivek's user avatar
  • 59
0 votes
0 answers
18 views

queryAllByRole('checkbox') works different depending on environment

I have a Vitest test that uses expect(screen.queryAllByRole('checkbox').length).toBeGreaterThan(0) Running in the WebStorm test runner, the test passes. Running via nx in the terminal (and in CI) ...
Jonathan Tuzman's user avatar
-1 votes
0 answers
19 views

Only the react-query test code does not run in Jest 29.7 with MSW 2.3.1

Currently, Jest is using version 29.7 and MSW is using version 2.3.1. When I set up MSW and wrote test code for React queries, it kept failing. However, if I create a random fetchMock and run the test,...
brgndy's user avatar
  • 65
0 votes
1 answer
30 views

Difficulty with getByLabelText in React

I have an input in a form with the following code... <div className="Field" id="choose-date"> <div className="field-title-icon"> <label htmlFor=...
Gordon Marshall's user avatar
0 votes
0 answers
13 views

How is a component with multiple setInterval() tested?

There are two setInterval() functions within a component I'm working on. Once the function start_new_game sets the component state variable level equal to '0', the component will invoke useEffect. The ...
0binny0's user avatar
  • 71
0 votes
0 answers
40 views

How to mock custom hook?

I want mock the getConversionList being called in useEffect. However since new to mocking need help import { useConversion, useOtherHooks } from "@custom/library"; const [ getConversionList,...
AKG's user avatar
  • 1
0 votes
0 answers
33 views

An issue with mocking 2 fetch requests for each test in React Testing Library

I am trying to mock 2 API requests in each test. See the code below to better understand what I mean: // exported mock request 1 export const mockSearchList = () => { return jest.fn(() => ...
Astw41's user avatar
  • 392
1 vote
1 answer
134 views

Vitest/React Testing Library - Error: Test timed out in 5000ms

In attempting to test setInterval() within the start_new_game() function nested within the <Simon /> component the following error is being raised: Error: Test timed out in 5000ms. If this is a ...
0binny0's user avatar
  • 71
0 votes
0 answers
18 views

Unit Test Repeatedly Fails When Trying To Remove Line Item From Cart (Vitest)

I'm relatively new to the world of writing unit tests and using Vitest so my issue might be quite obvious to someone more experienced but I can't for the life of me get the third test to actually ...
switchblade_comb's user avatar
0 votes
0 answers
20 views

Mocking internal change handler in MUI component

I am trying to write a test for the following code. It uses MUI components to render a checkbox with label. import React from 'react'; import { FormControlLabel, Checkbox } from '@mui/material'; ...
cdyswnnr's user avatar

15 30 50 per page
1
2 3 4 5
252