




















@@ -121,7 +121,9 @@ function expectLatestRequestTiming(
121121expected: Partial<RequestTimingPayload>,
122122) {
123123const timing = onRequestTiming.mock.calls.at(-1)?.[0] as RequestTimingPayload | undefined;
124-expect(timing).toMatchObject(expected);
124+for (const [key, value] of Object.entries(expected)) {
125+expect(timing?.[key as keyof RequestTimingPayload]).toBe(value);
126+}
125127expect(timing?.startedAtMs).toBeTypeOf("number");
126128expect(timing?.endedAtMs).toBeTypeOf("number");
127129expect(timing?.durationMs).toBeTypeOf("number");
@@ -304,18 +306,23 @@ describe("GatewayBrowserClient", () => {
304306});
305307306308expect(() => client.start()).not.toThrow();
307-expect(onClose).toHaveBeenCalledWith({
308-code: 1006,
309-reason: "security error",
310-error: expect.objectContaining({
311-code: "BROWSER_WEBSOCKET_SECURITY_ERROR",
312-message: expect.stringContaining("Use wss://"),
313-details: expect.objectContaining({
314-code: "BROWSER_WEBSOCKET_SECURITY_ERROR",
315-browserErrorName: "SecurityError",
316-}),
317-}),
318-});
309+const close = onClose.mock.calls[0]?.[0] as
310+| {
311+code?: number;
312+reason?: string;
313+error?: {
314+code?: string;
315+message?: string;
316+details?: { code?: string; browserErrorName?: string };
317+};
318+}
319+| undefined;
320+expect(close?.code).toBe(1006);
321+expect(close?.reason).toBe("security error");
322+expect(close?.error?.code).toBe("BROWSER_WEBSOCKET_SECURITY_ERROR");
323+expect(close?.error?.message).toContain("Use wss://");
324+expect(close?.error?.details?.code).toBe("BROWSER_WEBSOCKET_SECURITY_ERROR");
325+expect(close?.error?.details?.browserErrorName).toBe("SecurityError");
319326expect(wsInstances).toHaveLength(0);
320327321328await vi.advanceTimersByTimeAsync(30_000);
@@ -343,19 +350,24 @@ describe("GatewayBrowserClient", () => {
343350});
344351345352expect(() => client.start()).not.toThrow();
346-expect(onClose).toHaveBeenCalledWith({
347-code: 1006,
348-reason: "websocket error",
349-error: expect.objectContaining({
350-code: "BROWSER_WEBSOCKET_CONSTRUCTOR_ERROR",
351-message: expect.stringContaining("Could not create the Gateway WebSocket"),
352-details: expect.objectContaining({
353-code: "BROWSER_WEBSOCKET_CONSTRUCTOR_ERROR",
354-browserErrorName: "TypeError",
355-browserMessage: "constructor failed",
356-}),
357-}),
358-});
353+const close = onClose.mock.calls[0]?.[0] as
354+| {
355+code?: number;
356+reason?: string;
357+error?: {
358+code?: string;
359+message?: string;
360+details?: { code?: string; browserErrorName?: string; browserMessage?: string };
361+};
362+}
363+| undefined;
364+expect(close?.code).toBe(1006);
365+expect(close?.reason).toBe("websocket error");
366+expect(close?.error?.code).toBe("BROWSER_WEBSOCKET_CONSTRUCTOR_ERROR");
367+expect(close?.error?.message).toContain("Could not create the Gateway WebSocket");
368+expect(close?.error?.details?.code).toBe("BROWSER_WEBSOCKET_CONSTRUCTOR_ERROR");
369+expect(close?.error?.details?.browserErrorName).toBe("TypeError");
370+expect(close?.error?.details?.browserMessage).toBe("constructor failed");
359371expect(wsInstances).toHaveLength(0);
360372361373await vi.advanceTimersByTimeAsync(30_000);
@@ -436,12 +448,14 @@ describe("GatewayBrowserClient", () => {
436448error: { code: "CONFIG_ERROR", message: "config failed" },
437449});
438450439-await expect(request).rejects.toMatchObject({ gatewayCode: "CONFIG_ERROR" });
440-expect(onRequestTiming).toHaveBeenCalledWith(
441-expect.not.objectContaining({
442-params: expect.anything(),
443-}),
444-);
451+try {
452+await request;
453+throw new Error("expected config.get request to reject");
454+} catch (error) {
455+expect((error as { gatewayCode?: string }).gatewayCode).toBe("CONFIG_ERROR");
456+}
457+expect(onRequestTiming).toHaveBeenCalledTimes(1);
458+expect(onRequestTiming.mock.calls[0]?.[0]).not.toHaveProperty("params");
445459expectLatestRequestTiming(onRequestTiming, {
446460id: frame.id,
447461method: "config.get",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。