Replies: 2 comments 12 replies
-
Hi, @onmax. What you are doing in the first snippet should work. I believe MSW should handle the handshake request, but if you are still getting it as unhandled you can disregard that for now. Handshake succeeds, the WebSocket instance is created, and then The WebSocket mocking works with The issue must be someplace else. Can you please submit a minimal reproduction repo for this? Then I can take a look. Thanks. |
Beta Was this translation helpful? Give feedback.
-
UpdateI've taken a look at https://github.com/onmax/open-rpc-msw, here's my findings.
Apart from this, your initial approach for handling the HTTP handshake via I can see that MSW throws on constructing a mocked A quick verification that this one is on our end: expect(new HttpResponse(null, { status: 101 })).toHaveProperty('status', 101)
I will open a bug regarding this and ship the fix soon. What does this mean?Even with my fix, your setup still won't work. MSW currently doesn't support arbitrary WebSocket clients. I don't want to recommend you override import { WebSocket } from 'msw'
ws.link(url, {
WebSocket,
}) But this has its issues too, import order being the most important one (your |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have a project where I have implemented a WS client. Under the hood I use
@openrpc/client-js
, which usesisomorphic-ws
, which usesws@v7
.ws
is the Node implementation for Node and I am having a hard time trying to create test usingmsw
.Here is the test I have:
If I run it like that I will get an error and the connection is never opened:
So, I have implemented an HTTP handler which I have added in the
handlers
array:With that, it is seems to be returning the response but the web-socket and the connection is never open.
Not sure, why
ws
is making an http request (I guess for hand-shaking) and I am not sure how to solve the issue.I also tried to mock the
isomorphic-ws
library:But none of the solutions have worked...
I would like to know if anyone has ever manage to test the lib
ws
usingmsw
. I couldn't find anything in GitHub.Thank you!
Beta Was this translation helpful? Give feedback.
All reactions