master keaton
master keaton
TTCTheo's Typesafe Cult
Created by master keaton on 10/9/2023 in #questions
Has anyone had any success unit testing components which use tRPC apis?
I'm having a difficult time wrapping my head around testing react components that use trpc apis. Any success? Can you please share examples, posts, or repo links. I'm not talking testing tRPC procedures but unit testing components that use tRPC apis like this - api.upload_image.useMutation(). So far, I've got this - https://github.com/trpc/trpc/discussions/4899 But the problem I'm facing with this setup is that, while running tests, when I console log tRPC instance - api or api.upload_image.useMutation, from my component, it returns [Function: noop] which is no-operation function that makes no request for msw to intercep. How do I mock this api to use my mocked tRPC instance createTRPCReact that I created to unit test react components. Thank you.
1 replies