Questions tagged [react-testing]
116 questions
0
votes
0 answers
screen.debug() of Next.Js Link does not print anchor with href
In the Next.js application, I am using link tag in a component as following
{
…

paraS elixiR
- 1,866
- 1
- 18
- 26
0
votes
0 answers
window.scrollY coverage in jest
I want to test below snippet in jest .Anyone can help me to do this
`
const controlNavbar = useCallback(() => {
if (typeof window !== 'undefined') {
if (window.scrollY > lastScrollY) {
setScrollUp(false)
}
if…

Shamaz saeed
- 387
- 3
- 8
0
votes
0 answers
How to test window.addEventListener('scroll') in React Testing Library?
I have this hook in React I want to write the unit test but I faced the problem that I don't know how I could cover handleScroll function, how can I go to the useEffect to trigger the scroll event?
I tried fireEvent.scroll but not success.
import {…

iceCream
- 3
- 2
0
votes
0 answers
testing custom hook within a component scope throws TypeError not a function
when I run my unit tests to test componernts, I recieve errors similar to this one in multiple places:
TypeError: (0 , _fileName.useCustomHook) is not a function
when I test the hook itself alone it works fine, but I don't want to test the hook I…
0
votes
0 answers
Why window.location.assign() does not changes the window.location.href in react tests?
I am trying to test whether a window.location.href changes after a button is clicked. When in my component I use useNavigate to navigate to another page of my app, I can easily test the change of url. However when I try other navigation options like…

ptjr
- 11
- 2
0
votes
0 answers
Unit test case for addEventListener with throttle using jest - React
I have been trying to write unit test case for the following case.
Adding a scroll listener under componentDidMount to call infinity scroll method (Method covers under lodash throttle)
Code as follows:
Component
componentDidMount() {
…

stumps_k2001
- 45
- 1
- 5
0
votes
1 answer
UserEvent doesn't wait for dialog to be loaded when it is lazy load
After updating testinglibrary/userEvent from version 13 to 14, it is not waiting for dynamically rendered.
My dialog is lazily loaded as well as the content inside the dialog.
An example code is below.
it('updates the channel information after…

JunKim
- 647
- 7
- 17
0
votes
1 answer
React Jest Testing : How to test image is left aligned according to input parameter
I have to create react component having image and text box, so My task is to test
Image or Text box is Left or right aligned , as needed
Image or Text box is Top or bottom aligned, as needed
By passing input variant as textLeft or…

Thanos
- 45
- 1
- 10
0
votes
0 answers
Cannot read properties of undefined (reading '0') using React Testing library
I'm trying to get the instance of my app here, and I can't find a way to get it
with findInstance... here is my test
it('should call dispatchMWIUpdateError', () => {
const cmp = render( );
…

wonder.glen
- 46
- 7
0
votes
2 answers
React Jest test not working for number input
I'm writing a test that checks the input of 2 fields, one is type text and the other is type number.
I can grab the text input without issue and test it:
textInput = getAllByPlaceholderText('name');
userEvent.type(textInput[0], 'username');
This…

SlugLord
- 143
- 1
- 9
0
votes
0 answers
Test passing for button disabled when it should not (Formik | react-testing library)
I am using a formik form to sign up and testing it with react testing library. The submit button is disabled if the email or password fields are invalid. I am testing if my btn is enabled or disabled when i type certain input. I am performing 2…

H.b
- 239
- 2
- 13
0
votes
1 answer
Why did my asynchronous test in react not work?
Im testing a react component with jest and the react testing library (newest versions) and i dont get the asynchron tests to work. I assume its a syntax problem. The component gets rendert correctly, and the fetch (useEffect) also seems to work due…

Joshua Eisenberger
- 43
- 4
0
votes
2 answers
mock value inside the component file
I would like to ask if I have the variable useState in the component which is used as a condition that determines the element inside it will appear or not. How to mock the variable? So that I can test the element inside the condition if the value is…

syareen
- 328
- 2
- 4
- 15
0
votes
1 answer
Can't perform a React state update on an unmounted component in React Testing Library
I am testing custom written context for my application.
I have a interview-evaluations context file. I am trying to the fetchInterviewData functionality for this context provider.
/* eslint-disable prefer-destructuring */
/* eslint-disable…

Pratik Wadekar
- 1,198
- 8
- 15
0
votes
0 answers
How to test custom hook to and mock request api with react testing library
I'm trying to test custom hook that contains fetching api request
this is the code in useReportDownload.ts hook
import { useEffect, useState } from 'react'
import { useParams } from 'react-router'
import { fetchdownload } from '~/services'
export…

omar sobhy
- 23
- 3