diff --git a/src/plugins/runtime/runtime-channel.test.ts b/src/plugins/runtime/runtime-channel.test.ts index 8fa1b87f9af2..90a7aed52d81 100644 --- a/src/plugins/runtime/runtime-channel.test.ts +++ b/src/plugins/runtime/runtime-channel.test.ts @@ -1,6 +1,14 @@ import { describe, expect, it, vi } from "vitest"; import { createRuntimeChannel } from "./runtime-channel.js"; +function requireWatcherEvent(mock: ReturnType, index: number) { + const event = mock.mock.calls[index]?.[0] as { type?: string } | undefined; + if (!event) { + throw new Error(`Expected watcher event ${index}`); + } + return event; +} + describe("runtimeContexts", () => { it("registers, resolves, watches, and unregisters contexts", () => { const channel = createRuntimeChannel(); @@ -145,16 +153,8 @@ describe("runtimeContexts", () => { capability: "approval.native", }), ).toEqual({ client: "ok" }); - expect(badWatcher).toHaveBeenCalledWith( - expect.objectContaining({ - type: "registered", - }), - ); - expect(goodWatcher).toHaveBeenCalledWith( - expect.objectContaining({ - type: "registered", - }), - ); + expect(requireWatcherEvent(badWatcher, 0).type).toBe("registered"); + expect(requireWatcherEvent(goodWatcher, 0).type).toBe("registered"); lease.dispose(); @@ -165,16 +165,8 @@ describe("runtimeContexts", () => { capability: "approval.native", }), ).toBeUndefined(); - expect(badWatcher).toHaveBeenCalledWith( - expect.objectContaining({ - type: "unregistered", - }), - ); - expect(goodWatcher).toHaveBeenCalledWith( - expect.objectContaining({ - type: "unregistered", - }), - ); + expect(requireWatcherEvent(badWatcher, 1).type).toBe("unregistered"); + expect(requireWatcherEvent(goodWatcher, 1).type).toBe("unregistered"); }); it("auto-disposes when a watcher aborts during the registered event", () => { @@ -208,18 +200,8 @@ describe("runtimeContexts", () => { capability: "approval.native", }), ).toBeUndefined(); - expect(onEvent).toHaveBeenNthCalledWith( - 1, - expect.objectContaining({ - type: "registered", - }), - ); - expect(onEvent).toHaveBeenNthCalledWith( - 2, - expect.objectContaining({ - type: "unregistered", - }), - ); + expect(requireWatcherEvent(onEvent, 0).type).toBe("registered"); + expect(requireWatcherEvent(onEvent, 1).type).toBe("unregistered"); lease.dispose(); });