-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test React component using React Query's useSuspenseQuery
#164
Comments
Hello! It's hard to know what's going on here, but I suspect this is due to the details of Jest - by default Jest doesn't run in a real browser, but uses jsdom to emulate one, which can result in small weird differences in lots of places. One thing that could trigger this is that you're not specifying any headers with your stream. That's totally valid and it should work, but it's a bit unusual in real usage in HTTP, and I can imagine that Jest's mocks might not handle it correctly. What happens if you add One other thing is that you normally want to call If that doesn't work, I'm not sure what's going on, and it'd be helpful if you could set up a standalone repro to demonstrate this. |
Thanks a lot for your answer ! I added the header you mentioned with no significant change, then when I used |
Oh, that's a bit easier - in the code above at least, you're directly passing an object to the stream ( If you wrap your data into |
It doesn't :( |
Hmm, hard to say then. You may be able to add your own network logging somewhere to see exactly what's being sent and received, but that depends on your setup. I'm happy to investigate further myself, but I think this will need a standalone repro to be able to do so. |
I might do that if I find it's the solution I want to go for. Thanks for your support, I'll post again here if I need further help. |
Hello !
I'm trying to test my React component that's querying through a tRPC client using React Query's function
useSuspenseQuery
(for more info, click here).I'm using Jest and I'm mocking the tPRC server with Mockttp.
I suppose that when using
useSuspenseQuery
we should mock that query using a stream, so my test looks like this:I'm running my tests using
mockttp -c jest
as recommended in Mockttp's documentation. That part looks fine.My problem is that when running this test I'm having the following error:
I'm not super familiar with streams but I'm wondering if I'm using the right function from
mockttp
to mock theuseSuspenseQuery
or if I'm not passing the right thing tothenStream(...)
.Any help is appreciated, thanks !
The text was updated successfully, but these errors were encountered: