Skip to content

fix(site): add tests for createMockWebSocket #19172

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

Merged
merged 14 commits into from
Aug 7, 2025
Prev Previous commit
Next Next commit
docs: beef up comment
  • Loading branch information
Parkreiner committed Aug 7, 2025
commit dab74d71cc6a536f2386056c4bf9d95f3a02d71c
20 changes: 14 additions & 6 deletions site/src/testHelpers/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ type CallbackStore = {
export type MockWebSocket = Omit<WebSocket, "send"> & {
/**
* A version of the WebSocket `send` method that has been pre-wrapped inside
* a Jest mock. Most of the time, you should not be using the Jest mock
* features, and should instead be using the `clientSentData` property from
* the `MockWebSocketServer` type.
* a Jest mock.
*
* The Jest mock functionality only exists to help make sure that the
* client-side socket method got called. It does nothing to make sure that
* the mock server actually received anything.
* The Jest mock functionality should be used at a minimum. Basically:
* 1. If you want to check that the mock socket sent something to the mock
* server: call the `send` method as a function, and then check the
* `clientSentData` on `MockWebSocketServer` to see what data got
* received.
* 2. If you need to make sure that the client-side `send` method got called
* at all: you can use the Jest mock functionality, but you should
* probably also be checking `clientSentData` still and making additional
* assertions with it.
*
* Generally, tests should center around whether socket-to-server
* communication was successful, not whether the client-side method was
* called.
*/
send: jest.Mock<void, [SocketSendData], unknown>;
};
Expand Down
Loading