Skip to content

Commit

Permalink
self codereview
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Jun 3, 2021
1 parent 04b583c commit a8f8599
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ describe(`tryAssertionUntil`, () => {
});

test('exhausts all attempts before failing when assertion fails', async () => {
let attemptNumber = 0;
const subject = jest.fn().mockResolvedValue();
const assertion = jest.fn().mockImplementation(() => {
throw new Error('assertion error');
attemptNumber++;
throw new Error(`assertion error: ${attemptNumber}`);
});
let error;

Expand All @@ -38,9 +40,9 @@ describe(`tryAssertionUntil`, () => {
expect(error.message).toMatchInlineSnapshot(`
"Assertion failed after 3 attempts:
[
\\"assertion error\\",
\\"assertion error\\",
\\"assertion error\\"
\\"assertion error: 1\\",
\\"assertion error: 2\\",
\\"assertion error: 3\\"
]"
`);

Expand All @@ -49,8 +51,10 @@ describe(`tryAssertionUntil`, () => {
});

test('exhausts all attempts before failing when subject fails', async () => {
let attemptNumber = 0;
const subject = jest.fn().mockImplementation(() => {
throw new Error('subject error');
attemptNumber++;
throw new Error(`subject error: ${attemptNumber}`);
});
const assertion = jest.fn().mockResolvedValue();
let error;
Expand All @@ -64,9 +68,9 @@ describe(`tryAssertionUntil`, () => {
expect(error.message).toMatchInlineSnapshot(`
"Assertion failed after 3 attempts:
[
\\"subject error\\",
\\"subject error\\",
\\"subject error\\"
\\"subject error: 1\\",
\\"subject error: 2\\",
\\"subject error: 3\\"
]"
`);

Expand Down Expand Up @@ -134,7 +138,7 @@ describe(`tryAssertionUntil`, () => {
error = err;
}

expect(error.message).toMatchInlineSnapshot(`"Exepcting to at least attempt subject 1 time."`);
expect(error.message).toMatchInlineSnapshot(`"Number of attempts must be at greater than 1."`);
expect(subject).toBeCalledTimes(0);
expect(assertion).toBeCalledTimes(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function tryAssertionUntil<R>(
waitTimeMs?: number
) {
if (numAttempts < 1) {
throw Error(`Exepcting to at least attempt subject 1 time.`);
throw Error(`Number of attempts must be at greater than 1.`);
}

const attempts = Array.from({ length: numAttempts }, (_, i) => i + 1);
Expand Down

0 comments on commit a8f8599

Please sign in to comment.