diff --git a/extensions/zalo/src/api.test.ts b/extensions/zalo/src/api.test.ts index cdcef5a2dfb..919d6f0b4b7 100644 --- a/extensions/zalo/src/api.test.ts +++ b/extensions/zalo/src/api.test.ts @@ -18,8 +18,12 @@ async function expectPostJsonRequest(run: (token: string, fetcher: ZaloFetch) => await run("test-token", fetcher); expect(fetcher).toHaveBeenCalledTimes(1); const [, init] = fetcher.mock.calls[0] ?? []; - expect(init?.method).toBe("POST"); - expect(init?.headers).toEqual({ "Content-Type": "application/json" }); + expect(init).toBeDefined(); + if (!init) { + throw new Error("expected Zalo request init"); + } + expect(init.method).toBe("POST"); + expect(init.headers).toEqual({ "Content-Type": "application/json" }); } describe("Zalo API request methods", () => { @@ -67,7 +71,15 @@ describe("Zalo API request methods", () => { await rejected; const [, init] = fetcher.mock.calls[0] ?? []; - expect(init?.signal?.aborted).toBe(true); + expect(init).toBeDefined(); + if (!init) { + throw new Error("expected Zalo chat action request init"); + } + expect(init.signal).toBeDefined(); + if (!init.signal) { + throw new Error("expected Zalo chat action abort signal"); + } + expect(init.signal.aborted).toBe(true); } finally { vi.useRealTimers(); }