react-testing-library Questions

2

I have some code my React project which listens to a message event. const onMessage = ({ data }) => { console.log('On onMessage has been fired'); } window.addEventListener('message', onMessage...
Hudnall asked 12/8, 2021 at 11:5

4

Solved

What is the difference between enzyme, ReactTestUtils and react-testing-library for react testing? The ReactTestUtils documentation says: ReactTestUtils makes it easy to test React components i...
Dorolice asked 11/1, 2019 at 19:4

4

I am trying to basically just change a counter and show that the value has changed. I am doing this with getByTestId so that could be the problem ? Here is my component: import React, { useState...
Glendon asked 11/10, 2019 at 19:50

1

I have one component render a flyout as following HTML code once flyout is opened. I would like to write the test using test-library to verify the aria-expanded value is false after clicking the fl...

3

I tried to test a required input field with React Testing Library and Jest by testing the existence of the popover, but I failed. I tried several variants and none is working. The steps from UI are...
Wailoo asked 20/6, 2021 at 12:45

1

Solved

I can successfully implement a test with React Testing Library's fireEvent method, but when I try equivalent tests with userEvent I can't get it to trigger anything. How can I fix this? CodeSandbox...
Achaean asked 5/5, 2022 at 8:35

2

Solved

I'm trying to test that a component updates as it should due to changes in an input element. I use the fireEvent.change()-function, and if I then check the value of the node I found using getByPlac...
Decimeter asked 22/11, 2018 at 18:15

4

I'm trying to run a really simple test with react-testing-library where a button is given a mock function, the button is clicked, and the test checks that the function was called. However, the test...
Menorah asked 23/9, 2021 at 13:11

1

I need some help. I'm a newbie in apollo client reactive variables. There is a component where the displaying of the message depends on a variable that values from the local state (apollo cache). H...
Semivitreous asked 23/3, 2021 at 8:23

1

I'm getting the ECONNREFUSED error and it looks like my msw server isn't catching my get request when I start a get outside of a React component (which shaves some time off of the response). When a...
Longtin asked 21/4, 2022 at 21:37

4

Solved

I'm trying to mock axios.create() because I'm using its instance across the app and obviously need all of its implementation which is destroyed by the mock, thus cannot get the result of the get, p...
Ayurveda asked 27/2, 2020 at 7:58

2

Solved

I'm trying to test an Info HOC on my react app : const InfoHOC = (HocComponent) => ({ message }) => ( <> <Tooltip title={message}> <InfoIcon /> </Tooltip> {Ho...
Longeron asked 9/10, 2020 at 7:29

2

Solved

I am trying to write a few simple tests that the headers and data I want to render are showing up as expected. I created a repo - https://github.com/olore/ag-grid-testing-library to reproduce. The ...

1

Solved

I'm using React-18.0.0 in my project and in the test file I'm getting an error something below createRoot(...): Target container is not a DOM element. My test file is : import ReactDOM from 'reac...

2

As the title says, I'm using RTL + Jest (with Create-react-app setup). My question is if I should be using a beforeAll in each test pre-rendering the component within that block, so each test does...

1

Solved

I want to test a checkbox that has no label. The point is that there are other checkboxes as well so I cant use getByRole. I have tried to use data-testid, but apparently, it's not working. How am ...
Structure asked 5/4, 2022 at 12:20

2

Trying to learn testing. Using testing-library, Jest, and React-Router v6, and Typescript. I'm trying to figure out how to test a link. I've been looking all over the place for a solution and I can...
Basinger asked 31/1, 2022 at 21:57

1

Solved

I am running into a strange issue, would appreciate help here. I followed the example from here, can't tell what the heck is going on. The warning shouldn't be showing up, right? Component: Hello.t...
Craw asked 1/4, 2022 at 3:49

1

Solved

My component: import React from 'react' const TestAsync = () => { const [counter, setCounter] = React.useState(0) const delayCount = () => ( setTimeout(() => { setCounter(counter + 1...
Tessitura asked 27/3, 2022 at 18:21

1

I'm running into an issue when integrating my stories into my unit tests using Jest & React Testing Library in a NextJS app. In Storybook, my NextJS components render without issue with the Sto...
Novocaine asked 10/12, 2021 at 22:50

1

in react testing library, as per the conventions, it is better to use screen than to destructure the methods from render. I have a component, where I need to test the text that is rendered. The top...
Kirby asked 6/2, 2022 at 18:39

2

How to unit test the masked input field using react-testing-library. That component has developed using material ui and react-hook-form. Here you can find the code and worked on examples from my si...

1

We have noticed that our unit tests are performing very slowly and the culprit seems to be getByRole for querying for button elements etc. Here is an example of a query that was giving us problems ...
Sibelius asked 25/10, 2021 at 16:47

1

I am testing a combobox on first render the initial value of the combobox is undefined. Then using query parameters and a useEffect the the component find the relevant option and sets the value sta...

4

I'm testinng a react component using the RTL, and everytime I ran a test, I get, "messageParent" can only be used inside a worker **Here's the code describe('Header', () => { it('val...

© 2022 - 2024 — McMap. All rights reserved.