react-testing-library Questions

2

Solved

I need to test that a react component is called with opened={true} prop after an button click is fired. I am using testing-library ( testing-library/react + testing-library/jest-dom). I mocked the ...
Woadwaxen asked 18/11, 2021 at 11:46

2

Solved

I have a very simple component where I am trying to simulate an API call to get some movies with a slight delay. I want to write a test which tests that the movies are gathered and then rendered to...

3

Solved

The component that I have testing renders something this: <div>Text<span>span text</span></div> As it turns out for testing the only reliable text that I have is the 'span ...
Guardado asked 7/7, 2020 at 8:20

3

Solved

I'm following a tutorial on React testing. The tutorial has a simple component like this, to show how to test asynchronous actions: import React from 'react' const TestAsync = () => { const [c...
Fransen asked 14/1, 2021 at 19:20

2

Can't seem to get the value of an input using react-testing library, but for some reason one can set a value via fireEvent. nameInput is an actual input element test('verify name validation works',...
Southport asked 14/3, 2021 at 9:13

2

This question is really good: Jest Mock module per test It just don't answer my question on how to only mock it out in one single test and keep the rest using the original component. That would mak...

1

Immediately after npx create-react-app my-app, I move into the my-app folder and do CI=true npm test. The resulting output is: > react-scripts test PASS src/App.test.js ✓ renders learn reac...

14

I was trying to mock rejected value and got this error. It's weird that this construction works in the case of "success" addUser.mockImplementation(value => jest.fn().mockResolvedValue...
Impower asked 3/3, 2020 at 10:5

2

I am stuck here with a test where I want to verify that after scrolling through a list component, imported by react-window, different items are being rendered. The list is inside a table component ...
Ritornello asked 20/7, 2020 at 10:12

0

so recently we updated ag-grid-react and ag-grid-community from 27.0.1 to 28.0.0 and previous working tests now fail. Test tries to get a value from a row cell and compares to the given one. Test (...
Commixture asked 20/7, 2022 at 12:26

1

I'm testing a UI with the React Testing Library. Wondering if there is any way (including incorporating a separate package) to render the page being created by a test in my browser as I run the tes...
Galatians asked 19/1, 2022 at 1:0

2

Solved

Our app is wrapped in the MSAL Authentication Template from @azure/msal-react in a standard way - key code segments are summarized below. We would like to test app's individual components using rea...
Inchworm asked 21/6, 2022 at 2:47

3

Solved

I'm trying to change the value of the Material UI Datepicker Input with React Testing Library. But it doesn't seem to work with fireEvent.change(). import React from "react"; import { ren...

0

For example, there are two expect conditions like these: expect(firstItem).toHaveClass(firstStyle); expect(firstItem).not.toHaveClass(secondStyle); Is there a way to make them in one line? Somethi...

2

Solved

I'm following a simple tutorial to learn react testing library. I have a simple component like: import React, {useState} from 'react'; const TestElements = () => { const [counter, setCounter] ...
Gender asked 14/1, 2021 at 17:15

2

I am trying to test the drag and drop functionality using react-testing-libary. The drag and drop functionality comes from framer-motion and the code is in reacy. From what I understand it uses the...

0

The following test runs and passes just fine when using Create React App out of the box. import { render, screen } from "@testing-library/react"; import userEvent from "@testing-libr...
Bolen asked 22/6, 2022 at 0:58

1

I tried to test if my hover work or not , here's my code to be tested //styled components + typescript const Info = styled.div` opacity: 0; width:100%; height: 100%; position: absolute; top:0;...
Pentagon asked 11/10, 2021 at 12:41

2

I have been writing a test for my alert.js. I need to access prop value to test its severity. I tried lots of things. But failed every time. import React from 'react'; import PropTypes from 'pr...
Cuman asked 26/6, 2020 at 21:14

2

I am learning React Testing Library (many years of TDD experience in other languages) This documentation on the React Testing Library says that when getByText fails, it "however it prints the ...
Corymb asked 22/2, 2022 at 13:50

3

I want to test api call and data returned which should be displayed inside my functional component. I created List component which performs api call. I would like the returned data to be displayed ...

2

Using react-testing-library, the following test works: it( 'renders popular search terms, with links to search urls', () => { waitFor(() => { const popularSearch = screen.getByText( Copywr...

2

Solved

I understand that React Testing Library has an example of testing with react router, but I couldn't get it to work (I think because I am using react router V6). Basically, I need router testing bec...
Sapsucker asked 31/12, 2021 at 21:35

2

I am using jest and react testing library to test my react application. I wanna test a page that needs ISR (nextJs getStaticProps) to render so I installed next-page-tester package. It renders clie...
Caporal asked 29/7, 2021 at 23:44

10

Solved

I am trying to test my anchor tag. Once I click it, I want to see if the window.location.href is what I expect. I've tried to render the anchor, click it, and then test window.location.href: test...
Syncopation asked 6/9, 2019 at 18:40

© 2022 - 2024 — McMap. All rights reserved.