Son
Son3y ago

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);
});
2 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Son
SonOP3y ago
I see what you’re saying. Indeed i am a noob at this, thank you!