Questions tagged [react-testing]

116 questions
0
votes
2 answers

How to get the correct classname in React testing if there are multiple classnames in a single element?

I am writing a test case for a react component(Checkbox), Since, I am using a styled component there are multiple classes created. Now the problem is I need to write the test case such that I should be able to check a particular…
0
votes
1 answer

React Js API call Unit Test Case

I m trying to write test cases for my API I call but I don't know what I am doing wrong that I am getting errors like this. car.test.js import { getCar } from "../Service/MainScreen/Cars/Car"; describe("Car API Call function", () => { test("it…
0
votes
1 answer

How to mock a parent component which passes props to child component using react testing library

**How to check for the dynamic state changes in a parent component and write the test case using the react testing library if the props passed to the child component are based on the state changes which are happening dynamically in the parent…
0
votes
1 answer

Why can react-test-renderer only findByType functional components in the same file in React?

Here is the functional component some-table.jsx I am testing: import React from 'react'; const SomeTable = ({ somethings }) => ( <> {somethings.map(something => { return })} …
0
votes
2 answers

Mock function doesn't get called when inside 'if' statement - React app testing with jest and enzyme?

I am writing a test case for my react app and I'm trying to simulate a button click with a mock function. I'm passing the mock function as a prop and I'm calling the function inside an 'if' statement but the mock function doesn't get called and the…
0
votes
1 answer

Lit Element, unit testing - Nested Elements - Child element does not render

I am very new to lit-element and unit testing and am not sure if the question is even framed correctly. Please correct me if I am wrong anywhere. So, I have 1 lit component created such that it fetches the json from the uri
0
votes
2 answers

Unit Testing React Component using ReactBootstrap Modal with a Form Input element

I've react-bootstrap's Modal component which has an input and when i do the unit test for the Focus, it says it received whole document instead of just the Input element. Does any one know why the focus went to whole doc(Does Modal make the whole…
0
votes
1 answer

Mock service worker is unable to intercept network request

I have a react project in this git repo created from scratch without using create-react-app, so I am using jest.config.js and jest.setup.js files as suggested by msw doc for mocking network request for testing. I get the below error when I executing…
Thulasi
  • 126
  • 3
  • 19
-1
votes
1 answer

Dropdown selection using FireEvent in react-testing-library

I am working on the RTL and trying to test the dropdown selection. We have our component library which has custom controls. In this i fire select events on the custom dropdown. Here is the screen debug snippets Here is the screen debug output …
-1
votes
2 answers

Testing for disappearance of element using react testing library fails

I am trying to test disappearance of dialog box when user clicks "cancel" button on my dialog box using the following test: it("clicking on cancel hides the confirmation dialog", async() => { render(); const…
Anshul
  • 7,914
  • 12
  • 42
  • 65
-2
votes
1 answer

How test usestate and useEffect with click events using react testing library jest?

I am trying to test the useState functionality which is also updates when useEffect is called. The thing I am trying to test is at the initial stage the useState value is false then it changes on a click event. Please see the code I tried…
1 2 3 4 5 6 7
8