Questions tagged [react-testing]

116 questions
0
votes
0 answers

Showing Err For correct Code:'Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise'

I have entered the code right, and it worked too. But now i dont know why i am getting same error on different lines of code each time i test. The error comes at the chained commands. Sometimes its a chained Cy.find commands while sometimes its some…
0
votes
0 answers

React testing library - how to test setstate incustom onchange method of child component which updates state of child in parent component

I am new to react testing. I have a child component (to which I have no edit access) which is a table along with search box option. It has a event onSearchChange which will update the state with text if value entered in search box. Then we have…
0
votes
1 answer

Get error module not found in component file

I'm trying to write unit test. I just import my component file inside test.file. When trying run test. It gives error module not found for file import in file component, while in file component the import is working fine. Component file -…
syareen
  • 328
  • 2
  • 4
  • 15
0
votes
0 answers

How to test scrollHeight, scrollWidth, clientHeight and clientWidth with react-testing-library and jest

I just can't figure out, how I'm supposed to mock / get data from scrollHeight, scrollWidth, clientHeight and clientWidth in test. For better introduction, my task is to detect whether table element is scrollable or not and if it is, then I have to…
Pinnci
  • 423
  • 2
  • 5
  • 20
0
votes
0 answers

React Testing Library fireEvent.click() not Working

I have a component that updates the State on Button CLick, it works fine in the UI but causes my test to fail This is the initial state and the eventHandler. const [states, setMyStates] = useState("i Havent Clicked"); const changeVal = () => { …
0
votes
1 answer

React Testing Library works on HTML elements but not with React components

Basically, I'm trying to test a component that have a select. When trying to test the component, the test fails by returning the default value instead of the changed value. But when I take the HTML of the rendered component (from screen.debug()) it…
0
votes
1 answer

How to test React Number Format

I have used React Number Format package here and I want to test its onChange event but I'm getting an error, can someone please help me with this. I have given my test code and component below. In the fireEevent method of the code, it keeps saying…
0
votes
1 answer
0
votes
1 answer

Testing useQuery hook executed while loading page

I have been stuck with this problem for almost 2 weeks. I'm trying to create a POC with react-query to fetch information from an external source. This specific component should call a Service method and list the result in a result table. I'm mocking…
0
votes
0 answers

Mocking browser download functionality

I have a React component which internally creates a script DOM element. There is a bunch of logic around handling onload and onerror events of this script. The onload and onerror handlers are internal to the component, and I can't pass them via…
0
votes
1 answer

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 MyContainer extends React.Component { static…
0
votes
1 answer

Test fails with Content.Provider in React-Testing-Library

This is the react class that I want to test. I am using Content.Provider in order to keep a global state. In my testing file, I name it . import { useEffect, useContext } from "react"; import { Context } from '../../config/Store'; const…
0
votes
0 answers

How to test functions inside a React component

I'm having trouble trying to test functions declared inside a React component. In my case i have these functions called handleChange and changeCapacity , they're used by the Form.control element, it's a Select. I wrote a test that should use these…
0
votes
0 answers

Redux toolkit - testing store.dispatch causes infinite loop

I want to test async action changes store state correctly. However, when I make configure store and use store.dispatch, it causes infinite loop and test ends with timeout error. Here is my code. import { configureStore } from…
김진영
  • 11
  • 1
0
votes
1 answer

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 { MODAL_CONTENT_ADD_TO_ALBUM } from…