react-testing-library Questions

9

Solved

If anyone can help, I have a custom hook that uses ResizeObserver to change the width of a component. My problem is that when I go to run my units test it breaks all my tests and looking at the sna...

5

I am following the docs for react-testing-library to find if the element with data-testid attribute is rendered or not. The react-testing-library is not able to find the element even though it exis...
Clammy asked 9/6, 2021 at 4:24

3

Solved

I'm writing a React app using TypeScript. I use material-ui for my components and react-testing-library for my unit tests. I'm writing a wrapper for material-ui's Grid component so that I always h...
Exaggerated asked 3/11, 2018 at 15:35

1

I'm trying to test a React Server Component, which returns a Promise. The standard render method in Jest doesn't like that. I checked the similar questions, but all are > 4 years old and deal wi...
Goshorn asked 21/4, 2023 at 14:58

2

Solved

I'm trying to test a material ui text field using react-testing-library. The issue im facing is that in order to test the material ui textField i would have to use this property method screen.get...
Maida asked 27/5, 2020 at 17:44

3

Solved

Given that I can't test internals directly with react-testing-library, how would I go about testing a component that uses react-select? For instance, if I have a conditional render based on the val...

4

I have a problem when setting React Testing Library into a new project, which is a project that generates common UI components for several projects. In one of the projects it is correctly setup, bu...
Tattler asked 27/5, 2020 at 17:12

2

Solved

are there anyone see the problem here? If I put checked in state on change it works. But I don't want to duplicate the checked state data and watch it every single props change. Parent components g...
Excess asked 31/7, 2022 at 14:41

1

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      ...
Jarrad asked 8/5, 2023 at 17:5

2

I have a react component, which has two children, like this: import {Child1} from './child1'; import {Child2} from './child2'; ... return ( <> <Child1 /> <Child2 /> </> ...
Sodden asked 21/5, 2021 at 11:52

2

I have a beforeEach() that renders my app: describe('...', () => { beforeEach(() => { render(<App />); }); ... }); I am currently going through a config change in my app. config wa...
Humility asked 1/2, 2022 at 2:11

1

Solved

I have a test that generates the warning An update to DropDownMultiPick inside a test was not wrapped in act(...) And the warning points to this code : 10 | const toggleDropdown = () => { > ...
Misgiving asked 28/4, 2023 at 2:38

2

Solved

I have a fairly complex context that I wrap around my app to handle authentication and provide the associated data retrieved from the auth service. I'd like to bypass all of the functionality of th...

5

Solved

I have a (Jest) test to determine if a button exists: it('renders a signup button', () => { expect(sut.getByText('Sign up for free')).toBeDefined() }) This test because there is both a button ...
Starnes asked 16/10, 2019 at 7:40

2

Solved

I'm new to testing with jest and I want to test the following code. import React from "react"; import "./ButtonLogin.css"; import { Link } from 'react-router-dom'; function But...

4

I'm writing tests (with Jest and React Testing Library) for a form React component. I have a method that runs on form submit: const onSubmit = (data) => { // ... setIsPopupActive(true); // .....
Barrier asked 17/6, 2021 at 9:25

5

Solved

Currently I am writing a test to test the content that is inside (HTML content), but it seems I cannot test that properly with React testing library. It can find the id value of that, but how do I ...
Scholiast asked 2/6, 2020 at 11:38

1

I'm attempting to follow this guide in React Testing Library documentation to wrap all the components I want to test. I'm doing this because I need access to the various context providers that are ...
Hydnocarpate asked 6/5, 2019 at 1:17

0

I'm having trouble understanding the need of act and user events. I've read this issue and the linked blogpost but thats not exactly my case https://github.com/testing-library/user-event/issues/497...
Seldom asked 31/3, 2023 at 11:25

1

When I'm testing the <Link /> behavior, expecting it to redirect to a certain route, there's a TypeError (Cannot read property 'push' of null). This is the component I'm currently testing: im...
Awakening asked 17/2, 2021 at 10:9

2

Solved

Aim I am building a NextJS application that uses react-query to fetch data. I am now trying to implement a testing framework. However, when I run yarn test I get the error below. From the react-que...
Lear asked 13/1, 2021 at 0:26

2

I'm having trouble finding the correct way to test a div with text that is broken up by multiple elements - the error says 'Unable to find an element with the text: This could be because the text i...
Immutable asked 8/7, 2021 at 2:32

7

Solved

I am using user-event to try to have more 'realistic' user interactions. However, after I click on the input, it will not fire the onChange function because by default it would only bring up the fi...
Infarction asked 8/4, 2020 at 15:53

2

Solved

I have a component that calls to local storage and want to test it with jestJS. As far as I can tell jest does not support calls to localStorage. This is the component that I need to have tests for...
Wilcox asked 14/12, 2020 at 0:26

1

I am having trouble setting up the Jest and React Testing Library for the snowpack project and wondering if any of you have encountered something similar. So the error I am getting is The 'import.m...
Freer asked 29/11, 2021 at 19:39

© 2022 - 2024 — McMap. All rights reserved.