WebSocketSessionPair class final

Two WebSocketSessions connected to each other in memory: what one sends, the other receives, and closing one closes both.

It is the WebSocket a MockServerHttpRequest opens when the application accepts a handshake: the server end goes to the application, the client end to the test (MockMvc.webSocket). Use it directly to test code that takes a session without any HTTP.

// The code under test gets the server end; the test talks on the other.
final pair = WebSocketSessionPair(Uri.parse('ws://localhost/chat'));
startEcho(pair.server); // answers 'echo: <message>' to each message
pair.client.sendMessage('hello');
expect(await pair.client.messages.first, 'echo: hello');

Constructors

WebSocketSessionPair(Uri uri, {String? protocol})
Two connected sessions, both with uri and with protocol as their accepted sub-protocol.

Properties

client ↔ WebSocketSession
The end the test uses.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
server ↔ WebSocketSession
The end the application uses.
latefinal

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited