TRPC Testing Wrapper - Unit Testing components that contain a query (Not testing the query it self)
This is my wrapper
reference from trpc: https://github.com/WeirdoGit/NewGitRepo/blob/162cd9317c0e978ea2e666488a133838859cd50b/packages/server/test/react.test.tsx#L337
When ever i use it i get a
httpBatchLink
no fetch implementation error.
Can anyone help?
my test
GitHub
NewGitRepo/react.test.tsx at 162cd9317c0e978ea2e666488a133838859cd5...
Contribute to WeirdoGit/NewGitRepo development by creating an account on GitHub.
6 Replies
my current implementation is trying to call a function in the component but there is no context for it in my test i'm guessing, this is since removing the wrapper.
SOLVED: I had to share the same instance of the trpc client into my trpc mock. so I put it in global store and used that instance in my test and it worked.
You need to add a fetch implementation
To the httpBatchLink
Or a global fetch polyfill
Thanks for entering this thread! Really appreciate it. I’m a total noob tbh but I’m learning as i go.
Why do i need to add that and how should I implement it.
Im guessing i would need a mutation aswell? Or am I mixing things up here?
On the httpBatchLink there's a prop called fetch
Import node-fetch and put it in there
Typecast as any to get rid of type error if you need
Thank you, its only to get rid of type errors?
Is my mock the right way to go about it?
With the wrapper?
Or are you saying I don’t need the shared client? I just need to add the fetch prop
Thank you this is was the final solution
can this be added to the docs?