






















@@ -49,15 +49,12 @@ describe("postJsonWithRetry", () => {
4949});
50505151expect(result).toEqual({ ok: true, ids: [1, 2] });
52-expect(postJsonMock).toHaveBeenCalledWith(
53-expect.objectContaining({
54-url: "https://memory.example/v1/batch",
55-headers: { Authorization: "Bearer test" },
56-body: { chunks: ["a", "b"] },
57-errorPrefix: "memory batch failed",
58-attachStatus: true,
59-}),
60-);
52+const postJsonParams = postJsonMock.mock.calls[0]?.[0];
53+expect(postJsonParams?.url).toBe("https://memory.example/v1/batch");
54+expect(postJsonParams?.headers).toEqual({ Authorization: "Bearer test" });
55+expect(postJsonParams?.body).toEqual({ chunks: ["a", "b"] });
56+expect(postJsonParams?.errorPrefix).toBe("memory batch failed");
57+expect(postJsonParams?.attachStatus).toBe(true);
61586259const retryOptions = requireRetryOptions(retryAsyncMock.mock.calls[0]);
6360expect(retryOptions.attempts).toBe(3);
@@ -73,17 +70,21 @@ describe("postJsonWithRetry", () => {
7370Object.assign(new Error("memory batch failed: 503 backend down"), { status: 503 }),
7471);
757276-await expect(
77-postJsonWithRetry({
73+let error: unknown;
74+try {
75+await postJsonWithRetry({
7876url: "https://memory.example/v1/batch",
7977headers: {},
8078body: { chunks: [] },
8179errorPrefix: "memory batch failed",
8280retryImpl: retryAsyncMock as typeof import("./retry-utils.js").retryAsync,
83-}),
84-).rejects.toMatchObject({
85-message: expect.stringContaining("memory batch failed: 503 backend down"),
86-status: 503,
87-});
81+});
82+} catch (caught) {
83+error = caught;
84+}
85+86+expect(error).toBeInstanceOf(Error);
87+expect((error as Error).message).toContain("memory batch failed: 503 backend down");
88+expect((error as { status?: unknown }).status).toBe(503);
8889});
8990});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。