Skip to content
Discussion options

You must be logged in to vote

cy.intercept() doesn’t work with WebSockets, Cypress’s network layer only intercepts HTTP (xhr/fetch/document/etc.). WS Upgrade connections are piped straight through the proxy and never hit the interception middleware, so you can’t match, wait on, or stub them.

Your test opens a real socket, though, and the actual issue is that Cypress never waits for your async callbacks. You register onopen/onmessage and return immediately, so the test ends before a message arrives. Wrap the socket lifecycle in a promise Cypress can await:

cy.window().then((win) => {
  return new Cypress.Promise((resolve, reject) => {
    const ws = new win.WebSocket('wss://URL/v1')

    ws.onopen = () => ws.send(JSON.s…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jennifer-shehane
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants