WebSockets keep a two-way connection open so client and server can exchange messages. Test the connection lifecycle as well as message content.

Connection

  • Successful handshake returns 101 Switching Protocols.
  • Correct ws:// or secure wss:// URL is used.
  • Unsupported origin, protocol and version are rejected as designed.
  • Open, close and error states appear correctly in the UI.
  • Close code and reason are handled.
  • Idle timeout, ping/pong and server restart behaviour are defined.

Messages

AreaTests
SchemaRequired fields, types, version and unknown fields.
ValuesEmpty, boundary, malformed, Unicode and large payload.
OrderingRapid messages, late messages and sequence numbers.
DuplicatesRepeated event does not duplicate state unexpectedly.
BinaryCorrect type, size and decoding.
ErrorsInvalid messages do not break the connection or leak details.

Reconnection and reliability

  1. Connect and reach a known state.
  2. Switch DevTools to Offline or disconnect the network.
  3. Trigger or receive activity.
  4. Reconnect.
  5. Verify retry delay, connection status and missed-data recovery.
  • No endless rapid reconnect loop.
  • Subscriptions are restored once, not duplicated.
  • Messages are queued, dropped or replayed according to the contract.
  • UI does not show stale data as current.
  • Multiple tabs and devices behave correctly.

Authentication and permissions

  • Missing, invalid and expired credentials fail.
  • Token refresh or reconnect uses current credentials.
  • Logout closes or invalidates the connection.
  • User cannot subscribe to another user's private channel.
  • Role changes take effect as required.
  • Origin validation and message-level authorisation are enforced server-side.
  • Sensitive tokens are not placed in logged URLs when avoidable.

Debug with DevTools

  1. Open Network.
  2. Select the WS filter.
  3. Choose the WebSocket request.
  4. Inspect Headers for the handshake.
  5. Open Messages to inspect sent and received frames.
  6. Record timestamp, direction, payload and close details.
Evidence safety: WebSocket frames may contain tokens, chat content or personal data. Redact before sharing.

Useful tools and links