3,737 questions
0
votes
0
answers
58
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 (...
-1
votes
2
answers
459
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 ...
0
votes
1
answer
182
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
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
0
answers
87
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
1
answer
193
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
35
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: ...
-2
votes
1
answer
84
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
0
answers
116
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 ...
1
vote
1
answer
74
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(...
-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
vote
0
answers
42
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 ...
0
votes
0
answers
36
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
32
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 () => {
...
1
vote
1
answer
673
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
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
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
41
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/...
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 ...
1
vote
1
answer
825
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
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:
// ...
-1
votes
1
answer
366
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 ...
0
votes
1
answer
62
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 ...
0
votes
1
answer
256
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:
...