Questions tagged [react-hooks-testing-library]

Questions about testing React hooks with the react-hooks-testing-library utility.

react-hooks-testing-library

90 questions
0
votes
1 answer

React Testing Library - mock offsetWidth, offsetLeft

I need your help on fixing the test case. I am trying to mock the document body offsetwidth, offsetLeft objects. In the resize method, I am trying to mock the newWidth which is calculating the mouse position and accordingly getting the actual width…
0
votes
1 answer

Assert that a function changes a stateful value

So, here is a simplified version of my code. This is my custom hook. export const useStep = () => { const [step, setStep] = useState("sending"); const changeStep = (newStep: Steps) => setStep(newStep); return { step, changeStep…
0
votes
0 answers

React hooks unit testing React.memo on a function

How can I test this function wrapped in the React.memo , below is the function : const InternalDocuments = memo( forwardRef, InternalDocumentsProps>( ( { documentBlocks, …
0
votes
1 answer

`@testing-library/react-hooks` is loading my whole project?

I think this is an issue with module resoltuion/babel/typescript. When using @testing-library/react-hooks, I'm running into a strange stack: FAIL src/hooks/useAllPayouts.test.tsx ● Test suite failed to run TypeError: Cannot read properties…
HighFlyingFantasy
  • 3,789
  • 2
  • 26
  • 38
0
votes
1 answer

How can I grab multiple mapped elements using useRef?

Here I map though an array of objects that contain images to display on a page. At the moment when I try useRef it only grabs me the very last element. How can I have it so that my useRef grabs me multiple?
0
votes
1 answer

Unit testing a custom hook to ensure that it calls another hook

How can we ensure that a custom hook actually calls a method exposed by another hook? Let's say, I have a custom hook useName that internally leverages useState. import { useState } from 'react' export const useName = () => { const [name,…
0
votes
1 answer

How to test internal functions using react hooks testing library?

I have a custom hook that I am trying to write tests for using the react hooks testing library package and I would like to know how I can test internal functions that are not returned in the custom hook but are used within other functions. const…
0
votes
0 answers

Get State from React Hook Testing

I'm having a problem trying to access state and setState using react-hooks-testing-library. I've followed examples from various sources using Provider but it doesn't work Pay.tsx export const Pay = (): JSX.Element => { const location =…
0
votes
1 answer

How to spyOn to react custom hook returned value?

Here is my custom hook: useCustomModal.ts export const useCustomModal = (modalType: string) => { const setModal = () => { // ... functionality here }; const handleModalClose = (modalType: string) => { // ... functionality here …
0
votes
0 answers

Enable/disable submit button base on useState boolean values changes true/false using react jest testing library

I am populating the form fields from a configuration and after user updates the fields, I compare the updated fields with configuration fetched earlier using "isEqual". If "isEqual = false" I enable the submit button. I am having little trouble to…
0
votes
2 answers

can't build test to useOnClickOutside custom hook

I build a custom hook and I want to build test from it and I can't figure out where to start I would like you help to explain to me few things: 1.how I catch mousedown on the test 2. how I use the useRef and assigin it to current value It will be…
0
votes
1 answer

how to check axios get function called or not in react js?

I am trying to test below function or in other words I am trying to write unit test cases of below function.But I am getting error _axios.default.get.mockResolvedValueOnce is not a function import React from "react"; import axios from…
user944513
  • 12,247
  • 49
  • 168
  • 318
0
votes
1 answer

Custom Hook: how to test set state is not called on component unmount

Test set state is not called when component is unmounted I have got a custom hook which calls a promise on page load to set the data. To make sure that set state on data/error is not called when if the the component unmount I am using cancel request…
-1
votes
1 answer

Handling state of select tag in dynamic input field react

I do not understand why the state is registered yet it does not have an effect to the intended value of beds. Here is the main component const options = ["1", "2", "3"]; class Apps extends React.Component { constructor(props) { …
-1
votes
2 answers

React Intl Could not find required `intl` object. needs to exist in the component ancestry

I have used latest version of React-intl(^5.20.2). Trying to achieve Enzyme Unit testing in React hook component. but throwing this error "[React Intl] Could not find required intl object. needs to exist in the component ancestry." on UseIntl()…
1 2 3 4 5
6