react-testing-library Questions

3

I've successfully tested one isolated server component by using an async it and awaiting the output of a call to the component as a plain function to pass into render: it('renders the user data wh...

5

Here is how I am using MockedProvider. How can I mock refetch in mocks array? const mocks = [{ request: { query: GET_USERS_BY_FACILITY, variables: { facility: 300 } }, result: { data: { G...
Acicula asked 21/11, 2019 at 18:13

4

I am building a chat app and would like to write integration tests using react-testing-library and can not figure out how to mock socket.io-client's socket.on, socket.emit, etc. I tried follow thi...
Bradwell asked 3/10, 2019 at 2:44

5

Solved

I'm calling a function by finding the button with the data-testid with "show_more_button" <OurSecondaryButton test={"show_more_button"} onClick={(e) => showComments(e)} component="span" colo...
Herodias asked 29/5, 2020 at 14:23

3

Is it possible to maintain the same render() across multiple tests in using Jest and React Testing Library? I am building a Trivia App and have a single component that displays different questions ...
Barth asked 9/7, 2020 at 19:46

4

Solved

I have recently upgraded my React project to ant design v4 and all the tests that use a Select, AutoComplete or Tooltip are broken. Basically when clicking the components, the modal or select optio...
Hookworm asked 7/4, 2020 at 12:32

1

I have the following files in a React app with Vitest (which has the same API as Jest): // hooks/useEntities/useEntities.ts return useEntities() { // this hooks send api requests so I will mock i...
Cesar asked 15/12, 2022 at 15:46

5

Solved

I'm trying to understand how to best test that react-router behaves as expected with @testing-library/react. The simplest test I can think of, is to verify that clicking a link changes the URL. I ...
Neonate asked 18/5, 2020 at 12:45

4

With its user-centric approach, my understanding of RTL is that testing sorting of elements should look something like. const foo = queryByText('foo'); const bar = queryByText('bar'); expect(foo)....
Glossology asked 10/4, 2020 at 21:21

5

Solved

I got a custom hook which I want to test. It receives a redux store dispatch function and returns a function. In order to get the result I'm trying to do: const { result } = renderHook(() => { ...
Dionedionis asked 25/12, 2019 at 9:21

3

🙂 I'm learning testing in React, but fireEvent doesn't change value on my input. Unfotunanently, I don't know why? I'm rendering BuyPlace component. In this component I have form which has Input c...

6

I'm trying to upgrade my project to React 18, everything works in dev and production mode in the browser. But after upgrading to the latest version of @testing-library/react some of my unit tests a...
Villous asked 25/4, 2022 at 17:24

4

Solved

I'm trying to paste text that's already in my clipboard into a textbox, but I dont understand how to use "eventInit" to do this. I've read the documentation on how to paste text into a te...

3

I have written unit test using jest version 26.0.0 with react-testing-library and node version 14.2.0. Below is my React functional component which has a button, on clicking makes an ajax call to d...
Sivia asked 22/12, 2020 at 3:17

4

Solved

I migrated from React Router v5 to v6 following this tutorial. I want to test it with react-testing-library, but my old unit tests (using the pattern in this doc) stopped working. My app with React...
Selective asked 11/11, 2022 at 7:53

3

Solved

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....
Oldenburg asked 13/3, 2019 at 21:2

1

I'm getting this error when testing a component that uses react query custom hook: " No QueryClient set, use QueryClientProvider to set one " this is my hook: export default () => { c...

4

Solved

I'm getting TypeError: actImplementation is not a function when trying a simple test for this component import React from 'react'; import { StyledHeaderContainer, StyledTitle } from './styled'; ex...
Definition asked 1/4, 2022 at 9:27

2

Using React Testing Library to test a dialog provider. I can get it to open, and assert on it appearing — but for some reason I can't get it to close in the test. Do I need to rerender or something...
Jeremiad asked 20/9, 2019 at 15:44

4

Solved

I have a cutom hook that makes an API call on mount and handles state (isLoading, isError, data, refetch); The hook is quite simple: const useFetch = (endpoint, options) => { const [data, setD...
Peterson asked 28/7, 2022 at 9:14

2

I have a straight forward react-comp. which I want to test the styling depending on the react state. The comp looks like the following: React-comp. const Backdrop = ({ showBackdrop }) => { cons...

8

Solved

I'm using react-testing-libarary to test my react application. For some reason, I need to be able to find the element by id and not data-testid. There is no way to achieve this in the documentation...
Organdy asked 26/10, 2018 at 7:27

4

Solved

I'm must be missing something quite obvious, I have a react app that has a left div with multiple buttons, each one of them with different texts. I want to check if every one of those buttons was r...
Legitimist asked 15/11, 2020 at 13:11

6

Solved

I want to test the content of my material-ui datagrid but only the first 3 columns (out of 8) are rendered in the test. I can test the content of these 3 columns, no problem with that. Everything r...
Ila asked 11/1, 2021 at 15:27

2

I'm using create-react-app, Jest and react-testing-library for the configuration of the chatbot project. I have a React functional component that connects to a WebSocket server and DOM changes acc...
Girandole asked 29/11, 2019 at 8:29

© 2022 - 2024 — McMap. All rights reserved.