T
tRPC

testing a trpc hook

testing a trpc hook

TTCI11/18/2022
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);
});
UUUnknown User11/18/2022
2 Messages Not Public
Sign In & Join Server To View
TTCI11/19/2022
I see what you’re saying. Indeed i am a noob at this, thank you!

Looking for more? Join the community!

T
tRPC

testing a trpc hook

Join Server