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(); + }))); });