mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
|
|
test("WebSocket error event snapshot", async () => {
|
|
const ws = new WebSocket("ws://127.0.0.1:8080");
|
|
const { promise, resolve } = Promise.withResolvers();
|
|
ws.onerror = error => {
|
|
resolve(error);
|
|
};
|
|
const error = await promise;
|
|
expect(error).toMatchInlineSnapshot(`ErrorEvent {
|
|
type: "error",
|
|
message: "WebSocket connection to 'ws://127.0.0.1:8080/' failed: Failed to connect",
|
|
error: [Error: WebSocket connection to 'ws://127.0.0.1:8080/' failed: Failed to connect]
|
|
}`);
|
|
expect(Bun.inspect(error)).toMatchInlineSnapshot(`
|
|
"ErrorEvent {
|
|
type: "error",
|
|
message: "WebSocket connection to 'ws://127.0.0.1:8080/' failed: Failed to connect",
|
|
error: error: WebSocket connection to 'ws://127.0.0.1:8080/' failed: Failed to connect
|
|
,
|
|
}"
|
|
`);
|
|
});
|
|
|
|
test("ErrorEvent with no message", async () => {
|
|
const error = new ErrorEvent("error");
|
|
expect(error.message).toBe("");
|
|
expect(Bun.inspect(error)).toMatchInlineSnapshot(`
|
|
"ErrorEvent {
|
|
type: "error",
|
|
message: "",
|
|
error: null,
|
|
}"
|
|
`);
|
|
expect(error).toMatchInlineSnapshot(`ErrorEvent {
|
|
type: "error",
|
|
message: "",
|
|
error: null
|
|
}`);
|
|
});
|