3,736 questions
0
votes
0
answers
64
views
Unable to find element text from Backstage Table component in test (All components (2) not found)
I'm testing a Backstage plugin component that renders a list of Ansible components using the Backstage Table from @backstage/core-components.
In my test, I mock the catalog API to return 2 entities (...
0
votes
1
answer
82
views
testing an useState change inside a callback
I have a component like this to test:
import {doSomethingMocked} form 'mockedLibrary';
const TheComponent = (props) => {
const [isToTest, setIsToTest] = useState(false);
const handleClick = ...
-1
votes
2
answers
763
views
Next.js and Jest: TypeError `the "original" argument must be of type function`
I am new to Next.js but not to React and Jest; this is the first test suite I'm setting up in Next.js.
I have the following (extremely minimal, but this example does cause the error) component I am ...
-1
votes
1
answer
574
views
Test failure after upgrading to React Router v7.6.2
I am experiencing an issue after upgrading to React-Router version 7.6.2. I was able to replicate the failure: StackBlitz. Note that this test passed when I had v6 of React-Router-DOM.
The problem ...
0
votes
1
answer
217
views
Vitest react wait for function in useCallback to be in ready state
I have the following hook:
function useWelcomeMessage() {
const { data, error} = useGetWelcomeMessage();
const printMessage = useCallback(async () => {
if (data) {
alert(data)
...
0
votes
1
answer
33
views
How to Assert the Absence of an Element After an Async API Response in Testing Library
I'm wondering if it's better to use findBy together with rejects.toThrow instead of using queryBy with not.toBeInTheDocument when checking that an element is not displayed in cases like the following. ...
0
votes
1
answer
45
views
Testing library throws error with finding input element with slight change
I am testing my Input element by 2 way.
adding value and click on button to "todo list" works fine
adding value and enter the "input' field, but throws error.
I am seeking ...
1
vote
1
answer
156
views
React 19 'use', NextJS 15 async params and React testing-library
Using NextJS 14 and react testing-library, we previously used to test client components and client-only pages that take dynamic URL parameters like this:
type PageProps = {
params: { date: string }...
1
vote
0
answers
93
views
What exactly are the conditions that React will give the act warning?
I know that this is a well trodden topic, but most of the articles and help topics on this talk about how to avoid, and don't actually detail what exactly causes it.
I have a simple example of how we ...
0
votes
0
answers
95
views
Vitest: TypeError: Unknown file extension ".woff" in package from React TS project with vitest
I am trying to set up unit tests for a frontend project. Currently, i am trying to use vitest, since we use vite as well. Additionally i am going with HappyDom and TestingLibrary. Now, i am facing a ...
0
votes
1
answer
204
views
How can one test Chakra v3 UI Select in NextJS with Jest?
I'm building a NextJS (react) app with Chakra UI (version 3). I'd like to write unit tests, but I don't know to handle the way Chakra UI v3 handles select.
Here's a sample test app:
'use client';
...
0
votes
0
answers
128
views
How do i test Lexical Toolbar Plugin and trigger onError of initialConfig?
I am using ToolbarPlugin from Lexical and using the code from Lexical repo. My Sonarqube has flagged below code for test coverage and am not sure what test needs to be inlcuded:
`const $updateToolbar =...
0
votes
0
answers
39
views
When using react-query, how to write unit tests for the scenario of Dependent Queries?
how to write unit tests for useUpdateTodo hook without mock useGetUserId
// Get the user
const useGetUserId = ()=>{
const { data: user } = useQuery({
queryKey: ['user', email],
queryFn: ...
1
vote
1
answer
96
views
Can't successfully test a custom hook using useState and useEffect
While learning React, I'm trying to understand custom hooks.
I've created a simple one updating an internal "step" on creation, cleanup, and allows for external updates.
But I'm struggling ...
-2
votes
1
answer
101
views
Can anyone render react-router-dom components with react-testing-library?
After a lot of trial and error I cannot get RTL to render any components from react-router-dom. I am using [email protected], @testing-library/[email protected], @testing-library/[email protected], react-router-...
0
votes
1
answer
51
views
React testing library form validation
I'm stuck on a validation scenario in my Nextjs app, I have a form with some inputs and when a user tries to submit an invalid form an error message should be shown in the form.
However I think there ...
0
votes
0
answers
123
views
`usePathname` returning `null` despite mocking the return value - vitest
I'm currently writing UTs using vitest & react-testing library for my Next.js 14 application and I'm facing issues with the usePathname hook from next/navigation.
The usePathname hook is returning ...
0
votes
1
answer
429
views
How to test a loading screen in vitest
In my <App /> component I want to show a loading screen until I've fetched my data and after fetching my data all the images(whose source's I got from my data) are loaded.
I am having difficulty ...
1
vote
1
answer
75
views
How to make NextJS 15 dynamic CSS generation blank?
Earlier I was using NextJS 12 version & we stop generating the dynamic CSS class while writing the snapshot in React Testing Library by using the below method:
mocks\styled-jsx\css.js
function css(...
0
votes
1
answer
119
views
React Testing Library Fails to Detect :hover Styles in MUI Styled Components
I'm testing a styled button component in a Next.js 13+ App Router project using Jest and React Testing Library, but my tests fail when checking for style changes on hover.
Component (TestButton.tsx):
...
-2
votes
1
answer
55
views
Ensuring the correct drop down option selected from multiple select elements available
Using @testing-library/react": "^16.0.1", I would like to know the correct approach to handle my current scenario.
Here is my filter pane [using from Material UI filter slot similar to ...
-1
votes
1
answer
59
views
Why is the mock in my React unit test returning null
I have a hook that retrieves data from a firebase backend if the storage is clear.
The unit test keeps failing as a result of the null return value.
Here's the hook
import { useEffect, useState } from ...
1
vote
0
answers
45
views
How can I display a custom error message when a Jest snapshot test fails?
I have a simple Jest snapshot test, and upon failure, I would like to print a custom error message to remind the developer that if they intentionally failed the test, they need to ensure they update ...
1
vote
0
answers
184
views
Testing styled components from @emotion/styled with vitest
I am trying to assert that a component has a certain style in one of my tests. In the browser this component has the correct style but when I run my vitest test I get an incorrect style. It looks like ...
0
votes
0
answers
40
views
Test can't find conditional render component, disappearing too quickly
I am displaying a loading indicator whilst I wait for an async process to occur, however I believe my test might be missing it being displayed because the async process is too quick?
const [isLoading, ...
0
votes
0
answers
50
views
Mock react module to test error boundary for web-component
I am writing a React component that wraps an external web-component. Since this is external I want to wrap it in an error boundary.
Everything works in production, but I encounter some problems when ...
0
votes
0
answers
33
views
React 18 useState not updating the state after promise call in test cases
This is simple App.jsx
import React, { useState } from 'react';
const App = () => {
const [showDialogue, setShowDialogue] = useState(false);
const handleButtonClick = async () => {
...
0
votes
0
answers
48
views
React Test Error: Test suite failed to run, ReferenceError: global is not defined
I'm trying to push my brach-code for merging, but I'm stuck on this error after I tried running the command: npm test
Error: Test suite failed to run
ReferenceError: global is not defined
...
1
vote
1
answer
687
views
Why is my jest mock only returning the value in mockReturnValue the first time it's called in my test and not the 2nd?
I'm working on a React app that is tested with jest, and so far things have been going well. I have a component that relies on a service that shuffles a deck of cards. The component relies on this ...
0
votes
1
answer
62
views
Unable to render react-tooltip v5 using React Testing Library
With prior versions of react-tooltip, I was able to simply render the tooltip without even having to trigger a user interaction, with v5.28, even with userEvents, I am still unable to get the tooltip ...
0
votes
0
answers
59
views
Issue Setting Up babel-jest with React - Support for the experimental syntax 'jsx' isn't currently enabled
I am having an issue running tests with jest and RTL.
In my jest.config.js I have this:
const config = {
transform: {
".*": "babel-jest",
"^.+\\.(gql|graphql)$":...
0
votes
0
answers
453
views
SyntaxError: Cannot use 'import.meta' outside a module when doing unite test with React + vite + ts
I'm trying to set some unit tests, but since I use in my axios file import.meta I gives me this error. I've tried everything with babel, but still gives this error. My client doesn't want that I ...
0
votes
0
answers
26
views
Configuring Jest to render a component with alias
I'm using Jest with Testing Library on TypeScript. When I try to use the render function (from Testing Library) to load a component with this type of import, for example:
import backgroundImage from '@...
0
votes
0
answers
45
views
Unable to add a wrapper function using test library
I have this function which is used as a wrapper which is needed for multiple component test cases to pass. It's in a file called customWrapper.js.
So essentially I use render from here for other test ...
0
votes
0
answers
42
views
Cannot find module when running test in Jest
Im trying to setup tests for my company's app. The app runns perfectly, but when i run tests i get the following error:
Cannot find module @myCompany/custom-react-components from 'src/contentArea/...
1
vote
0
answers
149
views
React Testing Library/ Jest Dom (Custom Matcher) not..toBeDisabled() and .toBeEnabled (does not work as expected)
I am new in Jest and React Testing Library and want to test my Form created with Formik and Yup. The test should test when the User inputs invalid values, that the Submit Button should be disabled.
I ...
0
votes
0
answers
39
views
How to load content from CDN using react testing library
I am using NextJS with React Testing Library for component testing. I have a tinymce editor that loads from a CDN. When I tried to render my component which contains the tinymce component with React ...
0
votes
1
answer
105
views
TypeError: Cannot read properties of undefined (reading 'unsubscribe') with react hook form and React latest version in RTL test cases
We have recently upgraded our react app to use react-18.3.1 version along with the react-hook-form latest =7.54.1, but while running test cases we started getting below error:
42 | ...
1
vote
1
answer
845
views
React Router Outlet Not Rendering in Nested Routes While Testing with React Testing Library After Upgrading to v7
import { render, screen, waitFor } from '@testing-library/react';
import React from "react";
import { createMemoryRouter, RouterProvider, Outlet, createBrowserRouter } from 'react-router-dom'...
0
votes
0
answers
81
views
When using Jest-Cucumber with Jest and React Testing Library I get ReferenceError: _react1 is not defined
I am trying to test form inputs and button clicks with the screen object from React Testing Library and getting the following error when using Jest-Cucumber with React Testing Library: ReferenceError: ...
0
votes
0
answers
36
views
React: Cannot enter a value while testing NumericFormat embedded in Controller
I have a NumericFormat as part of a react-hook-form Controller which vitest renders with jest-dom. When trying to enter some test data into it, its value does not change.
The Component:
// ...
0
votes
1
answer
579
views
How to test asynchronous state update using zustand and jest?
Say I have a listStore.js like this:
import { create } from 'zustand'
import queryList from '@/service'
const useListStore = () => create((get, set) => ({
list: [],
getList: async () =>...
-1
votes
1
answer
374
views
A wall of red errors when testing MUI X Data Grid
I am introducing tests into my project and the thing I've encountered is that when I test the whole page component MUI X Data Grid table gives a wall of errors making it almost impossible to ...
3
votes
2
answers
2k
views
cannot detect installed react-router-dom package when running unit tests
I want to learn react testing library with react-router-dom. I created the app using npx create-react-app command. The resulting code already has an App.test.js in the parent folder:
import { render, ...
0
votes
1
answer
69
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 ...
2
votes
0
answers
1k
views
Error: Vitest failed to access its internal state
I'm creating a utility package that exports multiple tools like eslint, playwright, vitest, react testing library etc, and I'm using rollup to bundle the package.
However, when I install this package ...
2
votes
0
answers
133
views
React 18.3 causes a lot of `act` warnings in tests
I have the following component - "A toggle button":
// ToggleButton.tsx
export function ToggleButton() {
const [isEnabled, setIsEnabled] = React.useState(true);
return (
<button
...
0
votes
1
answer
268
views
Antd Select component does not show more than 2 options in tests
After going crazy around a test that refuses to pass, I realized that the Select component in the Antd library does not handle more than 2 options. I wrote the following test to explore the issue:
...
0
votes
0
answers
363
views
How to test custom hook with useEffect in React 18?
Hook:
import { useEffect, useState } from "react";
const useIsClient = () => {
const [isClient, setIsClient] = useState(false);
useEffect(() => {
setIsClient(true);
}, []);
...
-1
votes
1
answer
41
views
React Testing Library - mocking event.target.href automatically prepends domain upon click
I have a simple component like so:
const MyButton = ({ onLinkClick ) => {
const handleClick = e => {
e.preventDefault()
onLinkClick({ href: e.target.href, foo: 'bar', baz: '...