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
0 votes
2 answers
918 views

I'm using a custom react hook to perform two GET operations using react query. The API is in a separate module and uses both getTestByUid() and getTestStatuses() inside useQuery. // TestHook.js import ...
Tony96's user avatar
  • 41
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
0 votes
0 answers
301 views

I've created a widget component that can be embedded on a webapp as a script. It is not embedded in an IFrame therefore lives inside the webapp's window object. This embedded component is responsive ...
glengomerson's user avatar
1 vote
1 answer
354 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
290 views

I have this function inside a helper: export const useDAMProductImages = (imageId: string) => { const { app: { baseImgDomain }, } = getConfig(); const response: MutableRefObject<...
BlackWhite's user avatar
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
2 answers
3k views

Here is touchable element with navigation.navigate (react navigation 6.x), export default Home = ({ navigation }) => { .... return ( <TouchableOpacity testID={"...
user938363's user avatar
  • 10.3k
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 votes
1 answer
313 views

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"]; ...
lemu's user avatar
  • 64
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
0 votes
2 answers
533 views

Trying to install "react-google-login" by using the command npm install react-google-login. It gives the following error : npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve ...
Prajwal Raj's user avatar
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
1 vote
1 answer
1k views

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 ...
user901916'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
2 votes
1 answer
5k views

I've a custom React hook which uses react-query useQuery() in it-self: const useFetchSomething = () => { const { data, isLoading } = useQuery('key', ....); return ....... } I had to create a ...
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
4 votes
1 answer
3k views

With @testing-library/react-hooks I used to pass mocked store through initialProps just as mentioned in Advanced Hooks docs. Let's assume I have a code: import configureMockStore from 'redux-mock-...
Sasha Omelchenko's user avatar
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
1 answer
1k views

I have a custom hook, which has structure of: const urlHook = () => { const router = useRouter(); const read = () => { return validate(router.query.param); } const write = (params) => { ...
Alyona's user avatar
  • 1,792
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
0 answers
83 views

How can I test this function wrapped in the React.memo , below is the function : const InternalDocuments = memo( forwardRef<FormikProps<BlocksTypes>, InternalDocumentsProps>( ...
Lutaaya Huzaifah Idris's user avatar
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
3 votes
0 answers
2k views

Background: I've created a custom hook for useModal() to wrap some state for creating/destroying modals around the application: import { useState } from "react"; export default function ...
Tomuke's user avatar
  • 879
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
1 vote
0 answers
888 views

I am trying to use renderHook from the testing-library. When I run my test I get this error, TypeError: Cannot read property 'hasOwnProperty' of undefined package.json "devDependencies": { ...
Dharani Manickavasagam's user avatar
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
2k views

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 ...
Marcos Saucedo'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
2 votes
1 answer
2k views

I am attempting to test a basic Axios hook and am receiving: TypeError: globalObj.setTimeout is not a function at setImmediatePolyfill (node_modules/@testing-library/react-native/build/helpers/...
Dzone64's user avatar
  • 108
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
3 votes
1 answer
4k views

I'm trying to test a relatively simple custom hook that uses useEffect and setTimeout. However, my test fails, and I cannot figure out what is wrong. Here is the hook itself(useTokenExpirationCheck.ts)...
littlesvensson's user avatar
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
3 votes
2 answers
2k views

I am attempting to test a component that uses the useAsync hook using the @testing-library/react . If I use jest.mock on the TestAPI module, followed by getTest.mockResolvedValueOnce(testArray); on ...
Oliver Watkins'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
2 votes
1 answer
2k views

I using Firebase authentication and I would like to test the function using Jest and react-hooks-testing-library. I have a function that like this: const loginWithEmailPassword = (email: string, ...
ken's user avatar
  • 2,712
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
1 vote
1 answer
4k views

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 ...
Sai_91's user avatar
  • 33
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 votes
2 answers
9k views

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 ...
Vindhiya'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
2k views

I am not good at writing tests as far as non API functionalities are concerned I have tested using JEST with the help of rendererHook Just like below Sample correct TEST: import { render, screen, ...
Arslaan Muhammad Ali's 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
2 votes
2 answers
6k views

I am trying to test a simple custom hook: export const getSearchResults = async (searchText: string) => { const { data } = await axios.get(`${BASE_URL}/search`, { params: { searchText, ...
Dániel Kocsis'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
5k views

I´m writing some tests for my app and I´m trying to mock Linking module. I'm using jest. The Linking.canOpenURL mock it's working fine (toHaveBeenCalled is returning true), but openURL mock is never ...
Laurence Steven Montenegro'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
2k views

I am trying to write tests for this custom hook using react-hooks-testing-library. import { deleteArticleById } from '../../API/articles/deleteArticleById'; const useArticleDelete = () => { const ...
mkonav's user avatar
  • 13
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
4 votes
1 answer
4k views

For My project I am using one custom hook for navigation some of my screens as from one screen to another screen based on the parameters provide to the function of custom hook. How could I Unit Test ...
rchgupta's user avatar