From 3f874e41495736f55c9c3ca413310aa464833e5a Mon Sep 17 00:00:00 2001 From: Molly Draven Date: Thu, 30 May 2024 17:58:50 -0400 Subject: [PATCH] chore: Update TCPServer unit test for port in use error handling --- test/connections.spec.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/connections.spec.js b/test/connections.spec.js index 7eae72f..b16c892 100644 --- a/test/connections.spec.js +++ b/test/connections.spec.js @@ -3,7 +3,7 @@ import { describe, expect, it, vi } from "vitest"; import { TCPServer } from "../src/index.js"; describe("TCPServer", () => { - it("should return an error if the port is in use", () => /** @type {Promise} */(new Promise(done => { + it("should return an error if the port is priviliged", () => /** @type {Promise} */(new Promise(done => { const onListening = vi.fn(); const onConnection = vi.fn(); const onServerError = vi.fn().mockImplementation((err) => { @@ -16,4 +16,18 @@ describe("TCPServer", () => { const s = new TCPServer(80, onListening, onConnection, onServerError); s.listen(); }))); + + it("should return an error if the port is in use", () => /** @type {Promise} */(new Promise(done => { + const onListening = vi.fn(); + const onConnection = vi.fn(); + const onServerError = vi.fn().mockImplementation((err) => { + expect(err.message).toMatch(/EADDRINUSE/); + done(); + }); + + console.error = vi.fn(); + + const s = new TCPServer(8080, onListening, onConnection, onServerError); + s.listen(); + }))); });