All Questions
Tagged with react-testing-library react-redux
88 questions
0
votes
1
answer
18
views
I can't run jest snapshot tests because im constantly getting the ''Warning: Invalid hook call."
My components are working correctly, but I need to build snapshot tests for my react project, and I can't because of this error.
My data tests are running correctly.
Login.jsx
import React, { useState ...
0
votes
0
answers
42
views
onClick event not being handled/fired while testing - Custom component with Lit Element using React Wrapper
I have this below component that is a Header Component with an AccessBar and an Icon Component with certain props. All the custom components are actually Lit Element components (uses shadowDOM) from a ...
0
votes
0
answers
107
views
React Testing Library Hook testing: userEvent.selectOptions not firing onChange event handler
userEvent.selectOptions actually selects the value i set but its not firing the event listener that updates a hook
this is the component
import { useEffect, useRef, useState } from "react";
...
2
votes
1
answer
124
views
Not able to dispatch action in Jest
We have a cart component in the React app:
import { useDispatch, useSelector } from "react-redux";
import ItemList from "./ItemList";
import { clearCart } from "../slice/...
0
votes
1
answer
729
views
How to do unit testing of Modal in react using jest
// Delete.jsx
import React, {useCallback, useRef} from "react"
import {useDispatch} from "react-redux"
import {ModalComponent, modalOpen} from "../Modal"
export ...
3
votes
2
answers
3k
views
How to ensure that each test runs with a clean render using JEST/RTL?
I am unit testing a component form. The idea here is that the submit button is disabled and gets enabled when the form input is not empty. I'm doing that with a controlled input.
I have two tests in ...
3
votes
1
answer
4k
views
React Testing Library: Unable to find an element by: [data-testid="task"]
I am trying to test a Task component which renders after a form is submitted. I am using redux-toolkit, but the data-testid="task" which is the Task component never gets rendered in the test ...
0
votes
1
answer
719
views
How do I write a test for React Custom Hook that has useAppDispatch and ToolKitSlice?
I have my Custom Hook, it uses useAppDispatch and Slice from ReduxToolkit:
import { useAppDispatch } from "../../app/redux";
import { registrationFormSlice } from "../../entities/...
1
vote
0
answers
143
views
React-testing-library how to test conditional rendering
I'm new to react-testing, and I'm having problem with testing for this part of my code, because it is a conditional, and when I try to test it, it's assuming it didn't pass the conditional.
<div>...
0
votes
0
answers
127
views
How to mock useSelector
In my component
const pinnedLocations = useSelector((state) => state.page.pinnedLocations);
const User = useSelector((state) => state.user);
In my test file
import store from '../redux/store';
...
0
votes
1
answer
300
views
Failing test case if store state update in UI
I have setup a redux toolkit project for my learning and was going through a test cases, but going through multiple tutorial I got confused regarding how to write test case if a component includes ...
4
votes
2
answers
2k
views
Async thunks cause warnings in tests (wrapped in act)
When trying to test the component which dispatches async thunk I get the following warnings. They are displayed because of updates performed after the test is finished.
console.error
Warning: An ...
2
votes
0
answers
765
views
Mocking react-redux 8 reducer functions in tests using JEST and RTL
I have a react application with react-redux 7 written about 2 years ago. I wanted to update various third party libraries to the latest version and I run into an issue with migrating to react-redux 8.
...
5
votes
1
answer
2k
views
How to test react-router-dom views with data loader?
I have a React application with react-router-dom set up like this:
App.tsx:
import { RouterProvider } from 'react-router-dom'
import router from 'app/router'
createRoot(document.getElementById('root'...
0
votes
1
answer
2k
views
React Testing Library Unit Test Case: Unable to find node on an unmounted component
I'm having issue with React Unit test cases.
React: v18.2
Node v18.8
Created custom function to render component with ReactIntl. If we use custom component in same file in two different test cases, ...
5
votes
2
answers
28k
views
mock useSelector of react-redux with jest for test with react testing-library
I'm trying to test a component that uses react-redux for state management.
To test quickly I want to mock useSelector, like this:
const templates = [
{
id: ...,
name: ...,
...
},
{
...
1
vote
1
answer
842
views
How to include external library in testing library/storybook
I'm using Storybook to create stories. I want to create tests of the stories using @storybook/testing-react. However, I'm also using materialize-react which requires that materialize.min.js is loaded.
...
1
vote
1
answer
5k
views
Testing components with a request for rtk-query
I have started testing my React app and I have run into a problem - I can't test the components that are loaded from the server. Requests for uploading data are made via rtk-query, and I only know how ...
1
vote
0
answers
298
views
How to write unit test for render dynamic child component using map function in ReactJS(React testing library)
I have a list of questions in my array. Inside that array, there are questions, options, type, id.
I am rendering a component and using map function to iterate the array. If array has found type '...
0
votes
1
answer
12k
views
How to mock useState using Jest?
I am using Jest and react-testing-library in React application. I have to test following scenario -
function Parent () {
const [country, setCountry] = useState(true)
return (
<...
0
votes
1
answer
146
views
How do I test parameters in the saga files in React?
I am trying to write a unit test for a simple saga code snippet. Whenever I run any test I just get a message saying 'cannot read property 'param' of undefined.
const { param } = yield take(action....
0
votes
0
answers
725
views
testing react-redux with jest, actions may have undefined type property error
so testing a redux connecting container, I have multiple dispatch calls within. Most work fine, however, the action that returns types with array like so:
export const submitTest = () => ({
[...
0
votes
1
answer
467
views
Jest store state and RTL rendered component's onClick event handler different states
I'm using the following code to test a state-dependent react component using jest and rtl:
test("render author, date and image correctly after going next post", async () => {
const ...
2
votes
1
answer
4k
views
React redux toolkit testing with jest, how to dispatch asyncthunk and the state?
I want to write unit test which checks if data (onLoad) from dispatching async thunk is delivered into state.
It's first time when i'm writing unit tests and it's black magic for me.
My solution it's ...
0
votes
0
answers
446
views
Store does not have a valid reducer - React Testing Library / Jest
I switched our state management to redux toolkit. Now, of course, many tests fail, which I have to adapt accordingly. An error message is:
console.error
Store does not have a valid reducer. Make sure ...
3
votes
0
answers
378
views
jest throw symbol is not a function
I trying test a componet with name ContentPage (and managment store reac-redux). Bassically behaivour componente is redering in the first page only 8 cards with information about Breeds from ...
1
vote
1
answer
104
views
Reproducable asynchronous bug found in @testing-library/react
Unless I'm mistaken, I believe I've found a bug in how rerenders are triggered (or in this case, aren't) by the @testing-library/react package. I've got a codesandbox which you can download and ...
1
vote
1
answer
3k
views
TypeError: Cannot read properties of undefined - React Redux Toolkit Testing
In my React project I'm using redux toolkit and all is working fine on the UI side, but I'm running into the following error now I've come to testing my code (Note - I have chosen RTL as my library of ...
-1
votes
1
answer
1k
views
How to write Unit Test case for Switch Statement that returns Component in Jest with React Testing Library
When I writing test case, I was able to reach out to case 0, but not able to reach other 1
const tabContent = (isCurrent) => {
switch (isCurrent) {
case 0:
return <Component ...
1
vote
0
answers
95
views
Redux test using react-testing-library fails
I am testing a hook that internally dispatchs an action to fetch data and then it returns the value using the selector. I am using the approach suggested by react-testing-library and I am testing the ...
0
votes
1
answer
1k
views
React Testing Library - Cannot read property 'contents' of undefined] - value from redux
Am new in writing testcases using React Test library.
Here is my component
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
class ...
0
votes
1
answer
6k
views
Testing for SVG element in Jest (React-Redux)
I have a User component defined for a Reddit app like so:
// User.js
import React from "react";
import { useSelector } from "react-redux";
import { selectUsername, selectAuthState ...
-1
votes
1
answer
185
views
Getting an error message while testing react app
I'm getting this error message while testing one test in my mern app. I used redux to manage the state of the app.
I'm very new to testing react app.
Anyone please help me with this.
Error message:
...
1
vote
1
answer
2k
views
React/ReduxToolkit testing failed with "TypeError: Cannot read property 'pending' of undefined" when using Async Thunks
EDIT: PROBLEM SOLVED => https://github.com/reduxjs/redux-toolkit/issues/1609
Thanks to @markerikson
Im currently trying to setup tests into my project which is using React and ReduxToolkit. For ...
0
votes
1
answer
4k
views
How can I test the mapDispatchToProps with React-Testing-Library?
I have to test the below component :
import React from 'react';
import { connect } from 'react-redux';
import { open as openModal } from 'redux/actions/ModalActions';
import { ...
5
votes
0
answers
1k
views
How to setup React-Testing-Library with Redux-RTK (in typescript)
I'm using Redux to manage the state for my components. While it works on my application, I cannot get it to work within my react-testing-library testing suite.
Good news is, Redux-RTK has ...
0
votes
1
answer
230
views
How do I test a a Field component from React Redux with React Testing Library?
This is my Field:
<Field
name="postcode"
label="Postcode"
nonReduxFormInputProps={{ id: 'postcode' }}
component={TextInput}
/>
In my test, I've done this so far and it ...
0
votes
1
answer
136
views
Testing react components with redux-toolkit inside
I have a component like this:
export const DetailsItem: FC = (): ReactElement => {
const { isInEditMode } = useAppSelector(({ editMode }) => editMode);
if (isInEditMode) {
return <...
1
vote
2
answers
729
views
Could not find "store" in the context of "Connect(Items)". Either wrap the root component in a <Provider> in react.js?
I'm writing simple tests with counters using React Testing Library. I had failing tests because of the mentioned error that has to do with the store.
I tried to solve it using different approaches ...
1
vote
1
answer
13k
views
how to test a redux action that dispatch other action
I am using jest + react testing library
And as the title describes, what I am trying to test is that the testAction dispatch the secondTestAction, but I am getting an error saying the secondTestAction ...
47
votes
5
answers
122k
views
React Testing Library - Unable to find the element with data-testid
I am following the docs for react-testing-library to find if the element with data-testid attribute is rendered or not.
The react-testing-library is not able to find the element even though it exists....
1
vote
1
answer
1k
views
How to test React-Redux???(useSelector)
I am new to testing react-redux. I have a component named OTARequestDetails where the state of reducers is used and I am trying to access that state but getting the following error:TypeError: Cannot ...
2
votes
0
answers
2k
views
How to reset redux store after each test using @testing-library/react in Next.js?
I'm trying to get @testing-framework/react integrated into my Next.js workflow. To do that, I created a test-utils.js file as suggested in the documentation, where I re-export the render method with ...
2
votes
1
answer
961
views
How to render with router as well as with Redux for react-testing-library?
this is my testing-library-utils.js:
import React from "react";
import { render as rtlRender } from "@testing-library/react";
import { Provider } from "react-redux";
...
1
vote
2
answers
3k
views
how to fix React-Redux Provider and connect not available in jest
I wanna test a currently working react component with redux&hocks
using the default's react-cli test framework jest I made this test file
import React from "react";
import { render as ...
0
votes
0
answers
1k
views
Request Headers Causing ' Nock: No Match For Request'
Notable Tools I'm also using: React; Express.JS as my APi.
Output of Error:
onsole.error
pending mocks: ["GET http://localhost:5000/api/medias","GET http://localhost:5000/api/watching&...
63
votes
4
answers
43k
views
Testing Library React vs Jest
I have a really big application with react(lot of pages, modals, tables,etc) and I'm using redux-saga for managing the state. I have a lote of stores and almost in all the components I use the ...
0
votes
1
answer
70
views
How to test dispatched react function using Jest
I am trying to unit test a function which makes an async call using an Axios helper instance. I have attempted multiple ways of trying to unit test this but I can not seem to find any material online ...
2
votes
2
answers
4k
views
How to test a react connected component and what to test of component?
Following is a simple login component in my learning application.
I'm trying to write test of the following component via jest and testing-library/react
import React, { useEffect } from 'react';
...
0
votes
1
answer
1k
views
The initial state of redux/react-testing-library remains unchanged for the next test case
Here is my test file
describe("Header", () => {
// passed
it("should render a public header when the user is not authorized", () => {
render(<Header />, {
...