How to await useQuery result in a custom hook test

Hello,
So, I already know how to test a useQuery hook, and that it needs to await waitFor the success or error.

But how do you await a useQuery completion from "within" a custom hook ?

Code of my custom hook:
const useHasAtLeastPermissions = (requiredPermissions: Permission[]): boolean => {
  const { data, isSuccess } = useGetUserPermissions(); // the useQuery hook, successfully tested
  if (!isSuccess) return false;
  if (isSuccess && !data) {
    return false;
  }
  return requiredPermissions.some(requiredPermission => data.includes(requiredPermission));
};


Whenever I test it, it does not await the userPermission request, and doing an await waitFor(() => expect(result.current).toBe(true)) does not work 😦
Was this page helpful?