Questions tagged [react-testing]
116 questions
0
votes
0 answers
Testing for certain text using Vitest and React-Testing-Library after useEffect
My Dashboard component which is the parent component of the TopCards component which in turn is parent component of the Card1 Component
import TopCards from "./Dashboard/TopCards";
const Dashboard = () => {
useEffect(() => {
…

Prince Singh
- 87
- 6
0
votes
0 answers
Error while writing tests for a react component
I'm trying to write unit tests for an already existing React project.
These are the currently used versions,
"react": "^16.11.0",
"react-dom": "^16.11.0"
The project uses redux, but the component 'TechTable' doesn't use it. This is the component I'm…

pratibha negi
- 23
- 5
0
votes
1 answer
Mocking 3rd party React component in jest has no effect
I'm using jest with react testing library to provide basic testing for my React app. I have mocked the REST calls with msw.
Unfortunately one of the 3rd party libraries I'm using doesn't seem to render output properly in those tests and as I am more…

mikus
- 3,042
- 1
- 30
- 40
0
votes
0 answers
Playwright component testing timeout when intercepting multiple api requests
I am intercepting a network request beforeEach test while doing playwright component testing.
Here are my 2 test cases they run fine but if I put like 8 cases ( btn1, btn2, btn3, btn4 ... btn8) it gets timeout
until 6 test cases it works but not 8…

Divyanshu Rawat
- 4,421
- 2
- 37
- 53
0
votes
1 answer
How to mock axios call
I have a component Student component as follows
import axios from 'axios';
import React from 'react';
import { useEffect, useState } from 'react';
function Student(props) {
const [studentRecord, setStudentRecord] = useState(props.stRecord);
…

V R
- 133
- 1
- 8
0
votes
0 answers
TestingLibraryElementError: Unable to find an element Conditional based data-testid in @testing-library/react
I have written many test cases in the react testing library, I got stuck in the accessing condition based DOM element. I have tried many ways using import { renderHook } from '@testing-library/react-hooks'. But didn't work from me. Here is the code.…

Ramesh Lamani
- 1,117
- 3
- 25
- 54
0
votes
0 answers
React Testing Causing Error "Cannot use import statement outside the module"
I was doing react testing for my redux based application where i wanted to test my redux middleware. in the middleware i used
import axios from "axios"
then it shows error that Cannot use import statement ouside a module
`
FAIL …

Tahsin Ayman
- 11
- 1
0
votes
1 answer
how to test fetch request url in jest react test library
var checkBox = document.getElementById("myCheck");
var checkBoxChecked = "false";
if (checkBox.checked == true){
checkBoxChecked = "true";
}
const uri = 'https://jsonplaceholder.typicode.com/posts?exact' + checkBoxChecked;
const initDetails…

Manikandan Selva Cse
- 21
- 3
0
votes
1 answer
React testing library with React 16
We have a project built on React 16. It includes react-scripts test but I have failed to understand which testing framework is being used. So can we use react testing library to test react 16.4.
I would like to know how can I test react UI written…

Abhilash D K
- 1,223
- 1
- 23
- 39
0
votes
0 answers
GetByRole Unable to find an accessible element with the role "listbox" and name
I have a Kendo dropdown on a react page as follows

AIK DO
- 288
- 1
- 4
- 13
0
votes
1 answer
React testing `useEffect` with `useState` update
On my component render, my useEffects hooks called, a function. the function updates the state status depending on the condition within the useEffects produce.
So in this case how to test the `mobileMenu` and how to set different condition in…

hasina rajik
- 65
- 6
0
votes
0 answers
Jest: Cannot read property of undefined when importing from own package nextjs
Got this weird bug when running the jest test, one of the UI component from a self defined UI package keeps throwing error, saying that an object in that package is undefined...
The component itself works perfectly fine, and the same component's…

Shuwei
- 774
- 6
- 7
0
votes
0 answers
Why I'm getting error when trying to import axios, Cannot use import statement outside a module
I'm working on a reactjs project where I trying to learn the react-testing library with Jest. In my Login.jsx file when I'm trying to import axios, I'm recieving the following error.SyntaxError: Cannot use import statement outside a module
● Test…

Vidushika Dasanayka
- 117
- 9
0
votes
0 answers
How to write test for hooks by onclick method?
How do I write a test to activate the save button when I choose a date in the datepicker and the onclick function, which holds a state?here is a code snippet....
if (selectedDate?.filter((e: any) => e.employeeId === employeeId).length > 0)…

Sreyash
- 21
- 5
0
votes
0 answers
Create-daml-app testing not working,User already exists
I am following the tutorial here: Testing Your Web App to test the demo, but I got following error when I did npm run test:

Wenbo
- 43
- 3