mock-socket icon indicating copy to clipboard operation
mock-socket copied to clipboard

mock-socket configuration issue ?

Open maxpontreau opened this issue 3 years ago • 1 comments

Hello,

I working on an Angular projet. I'm trying to use a real websocket for my production code and the mock-socket for my cypress tests.

Here how I start the websocket in production (using sockjs-client & stompjs librairies) image

Now maybe I'm mistaken, but I was expected that with this code in cypress, the server would be mocked and the production websocket code would work: image

When launching cypress the websocket does not succeed to get a connection.

Where am I wrong ?

maxpontreau avatar Jul 15 '22 15:07 maxpontreau

Is the native WebSocket get called? You can check it by running the cypress in server mode. I'm not sure how the sockjs and stompjs are working. If so you can try mocking the WebSocket using the cy.stub:

import { WebSocket } from "mock-socket";
...
onBeforeLoad: () => {
  ...
  cy.stub(win, "WebSocket", (url) => new WebSocket(url));
},

Atrue avatar Jul 25 '22 13:07 Atrue