diff --git a/src/lib/MockClient.ts b/src/lib/MockClient.ts index 4e7e860..12bb7dd 100644 --- a/src/lib/MockClient.ts +++ b/src/lib/MockClient.ts @@ -36,4 +36,18 @@ export class MockClient extends MockPeer { this.wsServer.emit('connection', this.peerWebSocket, incomingMessage); }); } + + /** + * Connect to server, run `callback` and close the connection. + * + * @param callback The function to execute whilst connected to server + */ + public async use(callback: () => Promise): Promise { + await this.connect(); + try { + await callback(); + } finally { + this.close(); + } + } }