Skip to content

Commit

Permalink
[test] Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed May 21, 2022
1 parent fb658bd commit 8889e48
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions test/websocket-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,25 +340,30 @@ describe('WebSocketServer', () => {
wss.close();
});

it("emits the 'close' event if the server is already closed", (done) => {
let callbackCalled = false;
it('calls the callback if the server is already closed', (done) => {
const wss = new WebSocket.Server({ port: 0 }, () => {
wss.close(() => {
assert.strictEqual(wss._state, 2);

wss.on('close', () => {
callbackCalled = true;
});

wss.close((err) => {
assert.ok(callbackCalled);
assert.ok(err instanceof Error);
assert.strictEqual(err.message, 'The server is not running');
done();
});
});
});
});

it("emits the 'close' event if the server is already closed", (done) => {
const wss = new WebSocket.Server({ port: 0 }, () => {
wss.close(() => {
assert.strictEqual(wss._state, 2);

wss.on('close', done);
wss.close();
});
});
});
});

describe('#clients', () => {
Expand Down

0 comments on commit 8889e48

Please sign in to comment.