react-testing-library Questions

1

Solved

I am learning React-testing library and struggling to understand how to validate error messages with onchange. I even simplified it so the form is disabled until both inputs are valid. It works per...

5

Solved

I want to assert that an element never appears in my document. I know I can do this: import '@testing-library/jest-dom/extend-expect' it('does not contain element', async () => { const { query...
Perdita asked 15/7, 2021 at 20:37

15

Solved

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 f...
Thirteenth asked 15/3, 2019 at 13:47

4

Solved

I was taking a look to the waitFor documentation and I was wondering if there is any way to configure it globally, for example in the jest.config or in the command used to launch the test suite? I ...
Peltier asked 5/7, 2021 at 5:27

3

I have this Vitest test: import React from 'react'; import { expect, it, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; import { StyledNativeTimePicker } from '....
Hyperemia asked 6/12, 2023 at 9:44

2

Solved

I'm trying to test a component that uses react-redux for state management. To test quickly I want to mock useSelector, like this: const templates = [ { id: ..., name: ..., ... }, { id: ..., ...

7

I have this custom hook import { useLocation, useNavigate, useSearchParams } from "react-router-dom"; const useZRoutes = () => { const navigate = useNavigate(); const { search, hash...
Wessex asked 9/3, 2022 at 20:39

5

Solved

I'm building a React app with TypeScript. I do my component tests with react-testing-library. I'm buildilng a parallax component for my landing page. The component is passed the image via props a...

10

I have this test: import { render, cleanup, waitForElement } from '@testing-library/react' const TestApp = () => { const { loading, data, error } = useFetch<Person>('https://example....
Management asked 23/6, 2019 at 8:12

2

I have an input field and wish to stimulate the type-in during a unit test. Tried all the methods recommended on internet but still no luck, here is my code: // In component <div className=&quot...

3

Solved

When I import screen object like this import { render, screen } from '@testing-library/react'; it allows me to issue the following command: screen.findByTestId(...), but how can I search by data-te...
Cabbageworm asked 29/6, 2022 at 10:40

2

Solved

I am trying to test an input value of Search component via React Testing Library. Search component receives two props: handleChange and input value: title. My goal is to write the test so that init...
Eclosion asked 17/6, 2022 at 7:28

1

I'm currently making a react app with typescript, and I'm testing using react-testing-library. The app crashes with ReferenceError: jest is not defined. All of my tests pass though. Previously, ev...
Witted asked 14/3, 2019 at 18:50

4

I have a simple React component that will initially have a Tailwind CSS class of hidden which apply CSS display: none and will change the class to visible on button click. When I test with expect()...
Zingale asked 6/2, 2022 at 18:27

2

Solved

I am trying to use the user-event utility in testing library as described here : https://testing-library.com/docs/user-event/intro Unfortunatley when I try and call the setup function userEvent.set...
Grannie asked 10/5, 2022 at 12:6

3

Am trying to use react testing library on my project, but it isn't happy about the theme being passed to styled components in props, and I am getting this error:"TypeError: Cannot read propert...
Emanate asked 14/3, 2022 at 15:16

13

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/Te...

1

I am getting a TypeError when running my tests: TypeError: Cannot read properties of null (reading '_location') at Window.get location [as location] (my_files\characterbuilder\node_modules\jest-en...
Appanage asked 12/6, 2023 at 8:16

3

Solved

Following is a custom hook that I wish to test: import { useEffect, useState } from "react"; export const useAlert = () => { const [alert, setAlert] = useState(null); useEffect(() ...
Sik asked 17/4, 2022 at 10:48

6

I want to change the value of material UI TextField in react testing library. I already set up the data-testid. Then using getByTestId i picked up the input element. // the component <TextField...
Mechelle asked 19/7, 2019 at 10:33

2

when i use react-testing-library, it says that error: invariant expected app router to be mounted , it has no such problem when running in the development environment. the testing logics is here im...
Chymotrypsin asked 8/8, 2023 at 10:46

14

Solved

I have a component library that I'm writing unit tests for using Jest and react-testing-library. Based on certain props or events I want to verify that certain elements aren't being rendered. getB...

4

so I am trying to test that the onSubmit function is getting triggered if the button is clicked - the way im doing this is through testing the internals of the onSubmit function is getting calles (...
Twana asked 8/2, 2021 at 22:1

2

UPDATE: Tried upgrading to React 18 and RTL 13 but that did not fix the issue. React 16.4.0 react-scripts 5.0.1 Apollo Client 3.5.9 React Testing Library 12.1.2 I’m having chronic issues with tes...

3

Solved

I have a ant-design dropdown which shows a list on hovering the element. I want to test the list inside the dropdown menu. I am using fireEvent.mouseOver() but it doesn't work. screen.debug() shows...
Vanitavanity asked 11/11, 2020 at 12:51

© 2022 - 2024 — McMap. All rights reserved.