diff options
author | 2023-01-03 09:06:45 +0200 | |
---|---|---|
committer | 2023-01-02 23:06:45 -0800 | |
commit | 7edaf736a22d5d5b344932f1a290558cec5eb7fa (patch) | |
tree | 9ae49366cea441add4173ddde572d79c4f55a5f0 /test/bun.js/socket/socket.test.ts | |
parent | c770db7d52408bba14fe0d531b7b6bfae7b32cbd (diff) | |
download | bun-7edaf736a22d5d5b344932f1a290558cec5eb7fa.tar.gz bun-7edaf736a22d5d5b344932f1a290558cec5eb7fa.tar.zst bun-7edaf736a22d5d5b344932f1a290558cec5eb7fa.zip |
[socket] handle `connectError` (#1705)
assorted clean-ups & fixes
Diffstat (limited to 'test/bun.js/socket/socket.test.ts')
-rw-r--r-- | test/bun.js/socket/socket.test.ts | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/test/bun.js/socket/socket.test.ts b/test/bun.js/socket/socket.test.ts index aff001c75..7336306fa 100644 --- a/test/bun.js/socket/socket.test.ts +++ b/test/bun.js/socket/socket.test.ts @@ -1,6 +1,6 @@ import { expect, it } from "bun:test"; import { bunExe } from "../bunExe"; -import { spawn } from "bun"; +import { connect, spawn } from "bun"; it("should keep process alive only when active", async () => { const { exited, stdout, stderr } = spawn({ @@ -32,3 +32,40 @@ it("should keep process alive only when active", async () => { "[Client] CLOSED", ]); }); + +it("should handle connection error", done => { + var data = {}; + connect({ + data, + hostname: "localhost", + port: 55555, + socket: { + connectError(socket, error) { + expect(socket).toBeDefined(); + expect(socket.data).toBe(data); + expect(error).toBeDefined(); + expect(error.name).toBe("SystemError"); + expect(error.message).toBe("Failed to connect"); + done(); + }, + data() { + done(new Error("Unexpected data()")); + }, + drain() { + done(new Error("Unexpected drain()")); + }, + close() { + done(new Error("Unexpected close()")); + }, + end() { + done(new Error("Unexpected end()")); + }, + error() { + done(new Error("Unexpected error()")); + }, + open() { + done(new Error("Unexpected open()")); + }, + }, + }); +}); |