87 questions
0
votes
1
answer
282
views
testing-library/react-hooks calling a function that change the state
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 => {
...
0
votes
2
answers
921
views
How can I test two different GET queries in the same React custom hook using react testing library and react-hooks?
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 ...
1
vote
0
answers
399
views
react-hooks-testing-library: Context Provider, state change in child function act() error
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 ...
0
votes
0
answers
301
views
How to test this window resize hook?
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 ...
1
vote
1
answer
354
views
React testing custom hook with window.url
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)
...
0
votes
0
answers
290
views
How can I test useEffect with async function in Jest?
I have this function inside a helper:
export const useDAMProductImages = (imageId: string) => {
const {
app: { baseImgDomain },
} = getConfig();
const response: MutableRefObject<...
0
votes
0
answers
1k
views
result.current.data is undefined when I declare renderHook into the test closure but works when it is defined outside of it
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 ...
1
vote
2
answers
3k
views
TypeError: navigation.navigate is not a function in jest
Here is touchable element with navigation.navigate (react navigation 6.x),
export default Home = ({ navigation }) => {
....
return (
<TouchableOpacity testID={"...
1
vote
1
answer
2k
views
Testing custom hooks react typescript
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 = () => {
...
-1
votes
1
answer
313
views
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"];
...
1
vote
0
answers
2k
views
Vitest + MSW - Runtime request handler is not working
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 ...
0
votes
2
answers
534
views
not able to install react-google-login
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 ...
2
votes
1
answer
181
views
react page doesnt render when getting the data back from server
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 ...
1
vote
1
answer
1k
views
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 ...
4
votes
2
answers
9k
views
What is the suitable type for renderHook in react-testing-library and TypeScript?
I wanna test a custom hook with react-testing-library therefore, I add this code into beforeEach:
let renderedHook ;
beforeEach(() => {
renderedHook = renderHook(() => useFetch());
});
test('...