Questions tagged [react-testing]

116 questions
14
votes
2 answers

What is the alternative the function waitForNextUpdate (@testing-library/react-hooks) in @testing-library/react for async hooks?

I want to test my custom hook but in React 18 @testing-library/react-hooks library is not working, instead I am using @testing-library/react it has renderHook function and it works fine, but this library does not have waitForNextUpdate function for…
10
votes
1 answer

React + Jest Testing Error - ReferenceError: expect is not defined

I have literally trawled everywhere for an answer to this and possibly tried 99% of things out there so i decided to start a thread of its own so others can run their eyes over what i have currently and see if they can spot the issue. i am very new…
5
votes
1 answer

Can I have Jest Mocks in a different file and import it into my test file?

I have a custom Hook in a file and I have to mock it quite often for multiple tests. Can I have the mock in a separate file and then just import it into the test? Hook file export default function myHook(key) { const { state, app } =…
Kush Singh
  • 157
  • 3
  • 11
3
votes
2 answers

React Testing Library - How to see current state of the DOM when testing

I am learning React Testing Library (many years of TDD experience in other languages) This documentation on the React Testing Library says that when getByText fails, it "however it prints the state of your DOM under…
Jason FB
  • 4,752
  • 3
  • 38
  • 69
3
votes
0 answers

How to test FullCalendar's "dateClick" callback?

When the user clicks on the date in the calendar, the app should change the calendar's view to the week view of the clicked date. You can try it out in the sandbox: https://codesandbox.io/s/elastic-torvalds-ifedt?file=/src/App.test.js:100-503 You…
Filip
  • 31
  • 2
3
votes
1 answer

Unit testing for micro-frontend react application

I'm trying to write unit tests for a react spa web application that uses micro-frontend architecture. My first step is to write unit tests for the application container. The application container react component uses a react-router containing a…
Alex
  • 1,293
  • 1
  • 13
  • 26
2
votes
1 answer

react: docker-compose up not reloading after test

Is your proposal related to a problem? docker-compose up not reloading after test code changes. (I'm using vs code in a Windows) I used docker-compose up to run apps with React app containers and React app test containers. The react-app was…
2
votes
0 answers

Unable to access input component using react testing library

I am trying to check the value of input component, .i.e if the value equals==afghanistans then it will pass the test. Is there any way to access the this component using the provided name attribute('otherNames[0]')?
2
votes
1 answer

How do I properly test a custom fetch hook in react?

I have this custom hook that returns an object. It probably needs some improvement but for now it works as required. const fetchList = () => { const [list, setList] = useState(null); const [status, setStatus] = useState("idle"); const [error,…
2
votes
1 answer

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 warning below only occurs during the component Jests test.…
2
votes
0 answers

setTimeout working instead of await waitFor in test cases (Jest)

I am working on test cases in jest but the problem i am facing is that before i updated the @testing-library/react "await waitFor" was working fine but after the update they are giving error (ex: not giving the expected output) but when I put…
2
votes
2 answers

Writing a test to prove location for react-router

I'm fairly new to the world of writing tests for React so forgive the possible newbie question. I've done a fair amount of research and have not found anything that covers this as yet. I have a really simple BackButton component, all it does is…
2
votes
2 answers

React Testing Library -- Ignore Unneeded Side-Effects ("Not Wrapped in Act" Warning)

This minimum working example demonstrates what happens in a smaller test scenario: src/code.test.js: import {useState, useEffect, useCallback} from 'react'; import {render, waitForElementToBeRemoved, fireEvent} from…
2
votes
0 answers

TypeError: _axios.default.get.mockResolvedValueOnce is not a function

I'm trying to write a test using React-lIbraries and Jest. The test should render a mock axios that produces the mock data I've interested but I keep having the following error: TypeError: _axios.default.get.mockResolvedValueOnce is not a…
2
votes
0 answers

Issues with mock + multiple exports in the same file on react-testing-library

I am using Jest + React Testing Library in my project, and in one of my components, I have a common index.ts that exports all the internal components like: src/components/commonComponents/index.ts: import A, { IAProps as AType } from…
1
2 3 4 5 6 7 8