We are writing component test in cypress on a React-JS application which uses signalR for the websocket. Restful APIs are developed in dotnet core.
The test contains of usual cy.intercept commands trying to mock the APIs
While running the test the application is trying to reach a signalR endpoint '/testhub' internally and failing out giving the following error -
WebSocketTransport.js:49 WebSocket connection to 'ws://localhost:8080/testhub' failed: WebSocket opening handshake timed out
(uncaught exception)Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.
Below is the test file:
describe('<Jobs Page>', () => {
it('verify the data displaying in jobs page', () => {
cy.viewport(1000,1000)
//mocking the API
cy.intercept( "GET","api/jobs/testhub",{ fixture: 'testData.json'})
//Arranging or mounting a component
cy.mount(<Job/>)
})
})
We tried using "cypress-plugin-signalr", "socket.io-mock" plugins and mocking the websocket, but nothing fruitful.
Also not sure what is the endpoint signalR is expecting? The application UI are referring to 'http' urls whereas signalR endpoint is expecting 'ws'.