Skip to content

Commit 80236cb

Browse files
committed
test: update src/configurations.spec.ts
1 parent a9cd550 commit 80236cb

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

packages/middleware-retry/src/configurations.spec.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import { StandardRetryStrategy } from "./StandardRetryStrategy";
99

1010
jest.mock("./StandardRetryStrategy");
1111

12-
describe("resolveRetryConfig", () => {
12+
describe(resolveRetryConfig.name, () => {
13+
const retryModeProvider = jest.fn();
1314
afterEach(() => {
1415
jest.clearAllMocks();
1516
});
1617

1718
describe("maxAttempts", () => {
1819
it("assigns maxAttempts value if present", async () => {
1920
for (const maxAttempts of [1, 2, 3]) {
20-
const output = await resolveRetryConfig({ maxAttempts }).maxAttempts();
21+
const output = await resolveRetryConfig({ maxAttempts, retryModeProvider }).maxAttempts();
2122
expect(output).toStrictEqual(maxAttempts);
2223
}
2324
});
@@ -29,21 +30,28 @@ describe("resolveRetryConfig", () => {
2930
retry: jest.fn(),
3031
};
3132
const { retryStrategy } = resolveRetryConfig({
33+
retryModeProvider,
3234
retryStrategy: mockRetryStrategy,
3335
});
34-
expect(retryStrategy).toEqual(mockRetryStrategy);
36+
expect(retryStrategy()).resolves.toEqual(mockRetryStrategy);
3537
});
3638

37-
describe("creates StandardRetryStrategy if retryStrategy not present", () => {
38-
describe("passes maxAttempts if present", () => {
39-
for (const maxAttempts of [1, 2, 3]) {
40-
it(`when maxAttempts=${maxAttempts}`, async () => {
41-
resolveRetryConfig({ maxAttempts });
42-
expect(StandardRetryStrategy as jest.Mock).toHaveBeenCalledTimes(1);
43-
const output = await (StandardRetryStrategy as jest.Mock).mock.calls[0][0]();
44-
expect(output).toStrictEqual(maxAttempts);
39+
describe("creates RetryStrategy if retryStrategy not present", () => {
40+
describe("StandardRetryStrategy", () => {
41+
describe("when retryMode=standard", () => {
42+
describe("passes maxAttempts if present", () => {
43+
const retryMode = "standard";
44+
for (const maxAttempts of [1, 2, 3]) {
45+
it(`when maxAttempts=${maxAttempts}`, async () => {
46+
const { retryStrategy } = resolveRetryConfig({ maxAttempts, retryMode, retryModeProvider });
47+
await retryStrategy();
48+
expect(StandardRetryStrategy as jest.Mock).toHaveBeenCalledTimes(1);
49+
const output = await (StandardRetryStrategy as jest.Mock).mock.calls[0][0]();
50+
expect(output).toStrictEqual(maxAttempts);
51+
});
52+
}
4553
});
46-
}
54+
});
4755
});
4856
});
4957
});

0 commit comments

Comments
 (0)