test: tighten port probe rejection assertions

This commit is contained in:
Shakker
2026-05-11 05:14:11 +01:00
parent cfc189de0a
commit b9494a2dc5

View File

@@ -44,11 +44,18 @@ describe("tryListenOnPort", () => {
it("rejects when the port is already in use", async () => {
await withListeningServer(async (address) => {
await expect(
tryListenOnPort({ port: address.port, host: "127.0.0.1" }),
).rejects.toMatchObject({
code: "EADDRINUSE",
});
let rejection: NodeJS.ErrnoException | undefined;
try {
await tryListenOnPort({ port: address.port, host: "127.0.0.1" });
} catch (err) {
rejection = err as NodeJS.ErrnoException;
}
expect(rejection).toBeInstanceOf(Error);
expect(rejection?.code).toBe("EADDRINUSE");
expect(rejection?.address).toBe("127.0.0.1");
expect(rejection?.port).toBe(address.port);
expect(rejection?.syscall).toBe("listen");
});
});
});