You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having trouble making the following test pass and I was hoping you can help me.
import{useEffect,useState}from"react";exportfunctionuseComponentResources(required){const[componentResources,setComponentResources]=useState(null);useEffect(()=>{if(required){// api callsetTimeout(()=>setComponentResources({}),100);}},[required]);returncomponentResources;}
import{renderHook}from"@testing-library/react-hooks";import{useComponentResources}from"./component-resources.hook";describe("component-resources.hook",()=>{it("fetches resources when required",()=>{//actconst{ result }=renderHook(()=>useComponentResources(true));//assertexpect(result.current).toEqual({});});});
It keeps failing:
expect(received).toEqual(expected)
Expected value to equal:
{}
Received:
null
Difference:
Comparing two different types of values. Expected object but received null.
7 | const { result } = renderHook(() => useComponentResources(true));
9 | //assert
> 10 | expect(result.current).toEqual({});
11 | });
12 | });
I have created a repro case in codesandbox. Hopefully it makes it easier point out what I'm doing wrong:
I'm having trouble making the following test pass and I was hoping you can help me.
It keeps failing:
I have created a repro case in codesandbox. Hopefully it makes it easier point out what I'm doing wrong:
https://codesandbox.io/embed/priceless-browser-94ec2
The text was updated successfully, but these errors were encountered: