159 questions
0
votes
2
answers
4k
views
TypeError: Cannot destructure property 'data' of '(intermediate value)' as it is undefined - React Testing Library
I'm encountering an issue while testing a React component using React Testing Library. The component involves fetching data using Axios. The tests fail with the following error:
TypeError: Cannot ...
0
votes
1
answer
322
views
mock usePrompt in react-router-dom v6
Prompt.js
import { unstable_usePrompt as usePrompt } from 'react-router-dom';
// eslint-disable-next-line react/prop-types
export default function Prompt({ when, message }) {
usePrompt({ when, ...
0
votes
1
answer
73
views
How to test react component with jest?
I want to test the Sidebar component. When you click on the "ToggleButton" it should toggle sidebar by className, but when clicking, an error appears stating that the function was not found.....
1
vote
0
answers
139
views
How test a function that return JSX.Element and contains API request?
I have a custom function that show a user's card (returns JSX.Element) when the pointer is over the user's name. This component request user information using React Query, which I use for data-...
1
vote
1
answer
1k
views
Jest Snapshot tests failed after updating react native versions from 0.70.13 to 0.72.4
After Updating my react native version, I am keeping getting errors when I run the jest tests, it is regarding the snapshot tests for react redux connected components
React: 18.2.0
React Native: 0.72....
0
votes
0
answers
139
views
react-native jest and react-test-renderer always get error Element type is invalid and undefined
i try to write test for project in react-native for snapshot testing but when i run it always get error
Error: Element type is invalid: expected a string (for built-in components) or a class/function ...
3
votes
1
answer
143
views
React testing error 'unable to find element with the text
I'm struggling to get my 2nd React test to pass.
Here is my App.js file:
import logo from './logo.svg';
import './App.css';
import {useState} from 'react';
import {Link, Route, Routes} from "...
2
votes
1
answer
756
views
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely
Try to snapshot a Logo component but got an error that is not properait as far as i understand.
Pleas help!
logo.test.js
import TestRenderer from 'react-test-renderer';
import Logo from '../components/...
1
vote
2
answers
142
views
How to test a react native component whose UI changes based on async call in useEffect hook
I have a react native component OrdersScreen which I am not able to test because the component gets updated when setState : setRenderLoader(false) is called in React.useEffect() hook.
const ...
0
votes
0
answers
2k
views
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 ...
2
votes
0
answers
195
views
Apollo MockedProvider Immediately Returns Null
I am troubleshooting a failing React unit test that uses TestRenderer from react-test-renderer. My component queries a rest endpoint using GraphQL via the useQuery hook. If I wrap my component with &...
2
votes
1
answer
2k
views
Jest warning "Function components cannot be given refs." with TypeScript Functional Component Setup
The current setup is React 18 with the current versions of webpack, babel, typescript, jest & using the MaterialUI component library. Running/building the application produces no error & the ...
2
votes
2
answers
2k
views
TypeError: Cannot read properties of undefined (reading 'ReactCurrentOwner')
I have an npm monorepo which contains web apps (React 18), mobile apps (React-Native 0.71/React 18) and shared libraries. I am also using npm overrides to fix React versions, this has not changed. ...
3
votes
0
answers
235
views
Jest snapshot test throws "Cannot read properties of null (reading 'scrollWidth')"
I'm trying to write a snapshot test for one of the component in my app.
The component is built with some Antd components like Select.
i get the following error.
The tests
import React from 'react'
...
0
votes
1
answer
1k
views
react-test-renderer test failing TypeError: Cannot read properties of undefined (reading 'current')
I'm trying to do unit tests using react-test-renderer and I can't seem to make the test pass even though the underlying component I'm testing works. Can someone tell me what I'm doing wrong
This is ...
