Open tarehart opened 11 months ago
I found a better way of doing things that works with tRPC latest, I described it in https://github.com/trpc/trpc/issues/5134 and closed that issue.
Would you be interested in an integration test contribution that covers react hooks?
Hi thanks for your work! So just to make sure, the problem is with setting global.fetch like https://github.com/c-ehrlich/msw-trpc-example this example is showing?
Is this repo linked in the tRPC docs because I can't seem to find it?
Would you be interested in an integration test contribution that covers react hooks?
That would be nice, also we could add something about that to the readme?
Yes, setting global.fetch was the problem.
Nope, the repo is just something I found while googling, I never found an official recommendation on how to test with hooks.
My modified solution doesn't rely on setting global.fetch, but does still use the cross-fetch library. I'll go ahead and make a pull request to illustrate.
Describe the bug
Starting at exactly version https://github.com/trpc/trpc/releases/tag/v10.33.1, the useQuery hook no longer testable with msw-trpc in vitest. For some reason the msw proxy server never receives a request. Possibly useQuery is not calling fetch, or not calling fetch in a way that msw is able to intercept.
I also reported this to tRPC: https://github.com/trpc/trpc/issues/5134
I'm not sure if you can do anything to fix this, since my understanding is that msw-trpc only gets involved after msw's server receives a request.
As evidence that no request reaches the server, if I modify the test to have configuration like this, no error is thrown:
To Reproduce Steps to reproduce the behavior:
Expected behavior Test passes.
Test used to pass, this can be verified by pinning the tRPC versions to 10.33.0.
Versions