Skip to content

Commit

Permalink
feat(MockClient): Implement method to run callback whilst connected t…
Browse files Browse the repository at this point in the history
…o server
  • Loading branch information
gnarea committed Jul 28, 2021
1 parent 8886e93 commit 94a725a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lib/MockClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>): Promise<void> {
await this.connect();
try {
await callback();
} finally {
this.close();
}
}
}

0 comments on commit 94a725a

Please sign in to comment.