MCPcopy Create free account
hub / github.com/OneNoteDev/WebClipper / tests

Method tests

src/tests/promiseUtils_tests.ts:24–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 }
23
24 protected tests() {
25 test("execWithRetry should call the function once if the first attempt succeeds, and there are more than enough retries", (assert: QUnitAssert) => {
26 let done = assert.async();
27 PromiseUtils.execWithRetry(this.fnGenerator(1)).then((retVal) => {
28 strictEqual(retVal, this.expectedResolve, "execWithRetry should resolve with the same value the function's promise resolves with");
29 strictEqual(this.callCount, 1, "execWithRetry should call the function once");
30 }).catch(() => {
31 ok(false, "execWithRetry should not reject");
32 }).then(() => {
33 done();
34 });
35 });
36
37 test("execWithRetry should call the function twice if the first attempt fails, but the second succeeds, and there are more than enough retries", (assert: QUnitAssert) => {
38 let done = assert.async();
39 PromiseUtils.execWithRetry(this.fnGenerator(2)).then((retVal) => {
40 strictEqual(retVal, this.expectedResolve, "execWithRetry should resolve with the same value the function's promise resolves with");
41 strictEqual(this.callCount, 2, "execWithRetry should call the function twice");
42 }).catch(() => {
43 ok(false, "execWithRetry should not reject");
44 }).then(() => {
45 done();
46 });
47 });
48
49 test("With the default options, execWithRetry should reject if all attempts fail and there are not enough retries, and the callback should be called 4 times in total", (assert: QUnitAssert) => {
50 let done = assert.async();
51 PromiseUtils.execWithRetry(this.fnGenerator(Infinity)).then((retVal) => {
52 ok(false, "execWithRetry should not resolve");
53 }).catch((retVal) => {
54 strictEqual(retVal, this.expectedReject, "execWithRetry should reject with the same value the function's promise rejects with");
55 strictEqual(this.callCount, 4, "execWithRetry should call the function 4 times (1 first attempt, then 3 retries)");
56 }).then(() => {
57 done();
58 });
59 });
60
61 test("execWithRetry should call the function once if the first attempt succeeds, and there are 0 retries", (assert: QUnitAssert) => {
62 let done = assert.async();
63 let retryOptions: RetryOptions = { retryCount: 0, retryWaitTimeInMs: 0 };
64
65 PromiseUtils.execWithRetry(this.fnGenerator(1), retryOptions).then((retVal) => {
66 strictEqual(retVal, this.expectedResolve, "execWithRetry should resolve with the same value the function's promise resolves with");
67 strictEqual(this.callCount, 1, "execWithRetry should call the function once");
68 }).catch(() => {
69 ok(false, "execWithRetry should not reject");
70 }).then(() => {
71 done();
72 });
73 });
74
75 test("execWithRetry should call the function once then reject if the first attempt fails, and there are 0 retries", (assert: QUnitAssert) => {
76 let done = assert.async();
77 let retryOptions: RetryOptions = { retryCount: 0, retryWaitTimeInMs: 0 };
78
79 PromiseUtils.execWithRetry(this.fnGenerator(Infinity), retryOptions).then((retVal) => {
80 ok(false, "execWithRetry should not resolve");
81 }).catch((retVal) => {

Callers

nothing calls this directly

Calls 2

fnGeneratorMethod · 0.95
doneFunction · 0.85

Tested by

no test coverage detected