In my team we are using websockets to push some notifications that then update the state of the app. I tried to test changes in UI, but real data is to random and I have to mock it. Unfortunately, as for now I was unsuccessful. I tried to use @lensesio/cypress-websocket-testing plugin, but all I can do with it is catch real data and check what it was.
Is there a way to mock websockets in Cypress? I want my mocked server to send the message, that UI will display in browser and Cypress will assert if it's true. Something like cy.route for websockets.
Cypress does not currently provide a way to mock websockets out of the box. However, there are a few workarounds that you can use to achieve a similar effect.
One option is to use a library like sinon.js to mock the websocket connection and messages. You can use sinon.js to create a fake server that sends the desired messages to your application, and then use Cypress to verify that the application is behaving as expected.
Another option is to use a tool like ws to create a simple websocket server that you can run alongside your application during testing. You can then use this server to send the desired messages to your application, and use Cypress to verify that the messages are received and displayed correctly.