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
In @testing-library/react-hooks, the result object of renderHook() has an all property from which you can get the histories of the Hooks return value ( see docs ), which this library does not seem to have. I would like to see the all property added as it makes testing easier.
Suggested implementation:
The histories of returned values of Hooks can be obtained from the all property of the result object of renderHooks().
It is easier to verify the state in an asynchronous function.
exportconstuseData=()=>{const[data,setData]=useState<AnyData|null>(null);const[isLoading,setIsLoading]=useState(false);constgetAnyData=async()=>{setIsLoading(true);constfetchedData=awaitfetchAnyData();setIsLoading(false);setData(fetchedData);}return{ data, isLoading, getAnyData }}test("isLoading is changed from `true` to `false`",()=>{const{ result }=renderHook(()=>useData);awaitact(()=>result.current.getAnyData());expect(result.all[0].isLoading).toBe(false);// default valueexpect(result.all[1].isLoading).toBe(true);// start fetchingexpect(result.all[2].isLoading).toBe(false);// end fetching})
The text was updated successfully, but these errors were encountered:
The new renderHook APIs in React Testing Library and React Native Testing Library have not included result.all as it was deemed to promote testing implementation details. Tests that rely on result.all should be rewritten to just use result.current and/or waitFor with more emphasis on testing the value that will be observed by users and not the intermediate values in between observable results.
Describe the feature you'd like:
In @testing-library/react-hooks, the
result
object ofrenderHook()
has anall
property from which you can get the histories of the Hooks return value ( see docs ), which this library does not seem to have. I would like to see theall
property added as it makes testing easier.Suggested implementation:
renderHooks()
.Describe alternatives you've considered:
none yet.
Teachability, Documentation, Adoption, Migration Strategy:
It is easier to verify the state in an asynchronous function.
The text was updated successfully, but these errors were encountered: