fix: Resolve unhandled promise rejection in retry.spec.ts
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
The test "should verify exponential backoff timing" was creating a promise that rejects but never awaited it, causing an unhandled rejection error. Changed the test to properly await the promise rejection with expect().rejects. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -160,21 +160,25 @@ describe("Retry Utility", () => {
|
|||||||
expect(operation).toHaveBeenCalledTimes(4);
|
expect(operation).toHaveBeenCalledTimes(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should verify exponential backoff timing", () => {
|
it("should verify exponential backoff timing", async () => {
|
||||||
const operation = vi.fn().mockRejectedValue({
|
const operation = vi.fn().mockRejectedValue({
|
||||||
code: "ECONNREFUSED",
|
code: "ECONNREFUSED",
|
||||||
message: "Connection refused",
|
message: "Connection refused",
|
||||||
name: "Error",
|
name: "Error",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Just verify the function is called multiple times with retries
|
// Verify the function attempts multiple retries and eventually throws
|
||||||
const promise = withRetry(operation, {
|
await expect(
|
||||||
maxRetries: 2,
|
withRetry(operation, {
|
||||||
initialDelay: 10,
|
maxRetries: 2,
|
||||||
|
initialDelay: 10,
|
||||||
|
})
|
||||||
|
).rejects.toMatchObject({
|
||||||
|
message: "Connection refused",
|
||||||
});
|
});
|
||||||
|
|
||||||
// We don't await this - just verify the retry configuration exists
|
// Should be called 3 times (initial + 2 retries)
|
||||||
expect(promise).toBeInstanceOf(Promise);
|
expect(operation).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user