thoov / mock-socket

Javascript mocking library for WebSockets and Socket.IO
MIT License
800 stars 119 forks source link

Do you need to import the WebSocket in this example? #386

Open JJ opened 1 year ago

JJ commented 1 year ago

In this code

https://github.com/thoov/mock-socket/blob/47eab99d42b4f17abe8b7cc6ab1466cca6768750/README.md?plain=1#L39-L44

is WebSocket a regular one, or should it be imported from the library so that it can be mocked. In other word, is the URL mocked or the URL and the websocket?

Atrue commented 1 year ago

See https://github.com/thoov/mock-socket#stubbing-the-global window.WebSocket is stubbed out once new Server is called

JJ commented 1 year ago

See https://github.com/thoov/mock-socket#stubbing-the-global window.WebSocket is stubbed out once new Server is called

Right, but if you use this on the server-side, it does not look like it does.

Atrue commented 1 year ago

This library is intended for testing the client, so the WebSocket connecting to the mocked Server instead of the real one.

Server-side tests require another types of tests according to the server library implementation, so anyway you need to stub the protocol on the server.

If you want to use it on the server anyway, you need to import both WebSocket and Server from the library and write tests from the server perspective

JJ commented 1 year ago

That's exactly my point. Maybe a clarification in the example would help? After all, this example is simply under "Usage", no mention of the specific environment. I can craft a PR if that would help.