tRPCttRPC
Powered by
SonS
tRPC•4y ago•
3 replies
Son

testing a trpc hook

i'm brand new to testing and need some help with writing a test for a hook that is returning an object. im stuck with the error messages. i'm using trpc and react query
export function useGetTenantTickets() {
  const setTickets = useTenantStore((state) => state.setTickets);
  const { isLoading, isError } = trpc.ticketDomain.getByTenantId.useQuery(
    undefined,
    {
      onSuccess: (data) => {
        setTickets(data);
      },
    }
  );

  return { isLoading, isError };
}
export function useGetTenantTickets() {
  const setTickets = useTenantStore((state) => state.setTickets);
  const { isLoading, isError } = trpc.ticketDomain.getByTenantId.useQuery(
    undefined,
    {
      onSuccess: (data) => {
        setTickets(data);
      },
    }
  );

  return { isLoading, isError };
}


my test

 it('should return an object', async () => {
    const tickets = renderer.create(<TenantTicketsScreen />);
    const result = useGetTenantTickets();
    const expected = {
      isError: expect.any(Boolean),
      isLoading: expect.any(Boolean),
    };

    expect(result).toEqual(expected);
  });
 it('should return an object', async () => {
    const tickets = renderer.create(<TenantTicketsScreen />);
    const result = useGetTenantTickets();
    const expected = {
      isError: expect.any(Boolean),
      isLoading: expect.any(Boolean),
    };

    expect(result).toEqual(expected);
  });
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

trpc useError hook?
PeformPPeform / ❓-help
13mo ago
tRPC + cls-hooked
v1narthVv1narth / ❓-help
3y ago
Typing a shared TRPC provider for testing
itsravenousIitsravenous / ❓-help
3y ago