Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JJ opened this issue Oct 18, 2023 · 4 comments
Open

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

JJ opened this issue Oct 18, 2023 · 4 comments

Comments

@JJ
Copy link

JJ commented Oct 18, 2023

In this code

mock-socket/README.md

Lines 39 to 44 in 47eab99

import { Server } from 'mock-socket';
class ChatApp {
constructor(url) {
this.messages = [];
this.connection = new WebSocket(url);

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
Copy link
Collaborator

Atrue commented Oct 18, 2023

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

@JJ
Copy link
Author

JJ commented Oct 18, 2023

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
Copy link
Collaborator

Atrue commented Oct 18, 2023

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
Copy link
Author

JJ commented Oct 18, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants