how to bypass ws mocks
#2463
-
|
Hey team, I see that We relay on that function to toggle mocks via a button on the UI in development environments (for fetch calls). But now we are implementing mocks for I looked at https://github.com/mswjs/msw/blob/28d26bd7fa585d76f9ca69a67dfa70a234450ed9/src/core/ws/handleWebSocketEvent.ts but it seems it doesn't support a way to do it? I'd appreciate your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Hi, @csantos1113. You can bypass an intercepted WebSocket connection by establishing the server connection in your event handler. api.addEventListener('connection', ({ server }) => {
server.connect()
})Once you call Doing this in any matching handler will establish the connection to the original server. This means you don't have to call Let me know if this works for your needs or if you have any other questions! |
Beta Was this translation helpful? Give feedback.
Hi, @csantos1113.
You can bypass an intercepted WebSocket connection by establishing the server connection in your event handler.
Once you call
server.connect(), all the client events will be forwarded to the original server, and all the server events will be forwarded to your client. Your handler becomes, effectively, a proxy sitting in-between where you can decide which events to intercept, modify, or prevent forwarding altogether.Doing this in any matching handler will establish the connection to the original server. This means you don't have to call
server.connect()in multiple event handlers matching the same…