Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
281 views

I tried everything but still for some reason the react state doesn't change, what is I am missing or what is the alternative approach? Code: export const useCounter = (): UseCounterResult => { ...
mehran's user avatar
  • 1,494
1 vote
0 answers
397 views

I am using the React renderHook() function to call a custom hook. Internally in the custom hook, I call a function that executes axios, gets data and on success, dispatches a state change to a custom ...
Quinton's user avatar
  • 11
1 vote
1 answer
353 views

I have a custom hook that downloads a file from an url, it works fine and now I trying to test its behaviour. const useFileDownload = ({ apiResponse, fileName }) => { const ref = useRef(null) ...
heliosk's user avatar
  • 1,169
0 votes
0 answers
1k views

I'm trying to test a custom hook but for some reason I can't render the hook inside the test closure "it". This code works (I must use the rerender methods otherwise the result.current.data ...
jeyremd's user avatar
  • 309
1 vote
1 answer
2k views

Im learning react testing and i have this hook i want to test but i have no idea how import { useState, useCallback } from 'react'; import axios from 'axios'; export const useFetch = () => { ...
ludinj's user avatar
  • 125
1 vote
0 answers
2k views

I'm trying to migrate the test framework of my app from Jest to Vitest (for multiple reasons) and I encounter an issue. With Jest, I was using runtime request handlers at multiple places of my app to ...
Yomansk8's user avatar
  • 243
2 votes
1 answer
181 views

react won't work when rendering the page, but when i changed code in the vscode (added a line of console or comment one line out), the page is rendered. or when page is not rendered. when i hit ...
gongonlittle's user avatar
4 votes
2 answers
9k views

I wanna test a custom hook with react-testing-library therefore, I add this code into beforeEach: let renderedHook ; beforeEach(() => { renderedHook = renderHook(() => useFetch()); }); test('...
Martin Rützy's user avatar
5 votes
2 answers
10k views

The [deprecated?] react-hooks-testing-library would return any errors thrown by the hook under test. Probably my misunderstanding, but it looks like implementation now in the main @testing-library/...
Eric's user avatar
  • 1,195
0 votes
1 answer
198 views

So, here is a simplified version of my code. This is my custom hook. export const useStep = () => { const [step, setStep] = useState<Steps>("sending"); const changeStep = (...
Augusto Oliveira's user avatar
1 vote
0 answers
2k views

I am trying to write some unit tests for my input components, most of them are connected to Formik and there are cases like my Autocomplete component where the form gets validated when the user ...
Sakis95's user avatar
  • 49
0 votes
1 answer
201 views

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 ...
HighFlyingFantasy's user avatar
1 vote
1 answer
798 views

I have a hook that detects the orientation of a React Native Image: import { useState, useEffect } from 'react' import { Image } from 'react-native' const useFindImageSize = (image) => { const [...
bopbopbop's user avatar
  • 522
2 votes
2 answers
2k views

I have a custom hook that dispatches an action when a URL parameter changes: export const useUser = (): void => { const dispatch = useDispatch(); const { user } = useParams<{ user: string }&...
Andy Jessop's user avatar
0 votes
1 answer
3k views

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' ...
Muhammad Kashif Nazar's user avatar
8 votes
1 answer
5k views

There is an example on advanced-hooks#async doc. I am confused about how does waitForNextUpdate works. I made two test cases to compare waitForNextUpdate and act() + jest.advanceTimersByTime(). index....
Lin Du's user avatar
  • 104k
2 votes
1 answer
1k views

Why does destructuring need waitFor? Codesandbox All tests do the same thing. In the 'ok.test.ts' file I use renderHook, I use result.current[1] to set the state and result.current[0] to get the ...
Eduardo Dallmann's user avatar
2 votes
1 answer
2k views

I am testing the custom React Hook shown below. Its functionality is to get the size of an image and then use the props provided to calculate the size of the image that the user wants. import { ...
pumpum's user avatar
  • 665
1 vote
1 answer
860 views

I using Firebase auth in React, and I try to test it with react-hooks-testing-library. The code I write is working. But when I try to test with react-hooks-testing-library I get this error: ...
ken's user avatar
  • 2,712
2 votes
1 answer
2k views

Hi all I am new to jest and now working on some tests for our customHooks. My customHook has useEffect inside and does not return value: const useCustomHook = (func: EffectCallback, deps?: ...
Victor Cheng's user avatar
1 vote
1 answer
3k views

I've written a simple React hook and want to test it with react-hooks-testing-library. This hook calls an async function once both provider and domain variables, then once it's resolved puts data in ...
user avatar
2 votes
1 answer
6k views

Look at the following custom hook. The premise is that it updates its state when query changes. export function UseCustomHook() { const { query } = useRouter() const [state, setState] = useState({}...
user10741122's user avatar
0 votes
0 answers
378 views

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 = ():...
Sofyan Setiawan's user avatar
3 votes
1 answer
3k views

I have question about react-testing-library with custom hooks My tests seem to pass when I use context in custom hook, but when I update context value in hooks cleanup function and not pass. So can ...
Gianluca Escobar's user avatar
1 vote
1 answer
4k views

In this example we have a simple hook called useLog that returns a method. How do I test that it gets returned with react-hooks-testing-library. I am trying to figure out how to write the expect. The ...
someRandomDude's user avatar