Skip to content

Commit

Permalink
adding error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Aug 9, 2024
1 parent ea0a094 commit 46530e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions test/ops/retry/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,30 @@ export default () => {
});
it('must pass correct callback parameters', async () => {
const ind: number[] = [],
att: number[] = [];
att: number[] = [],
err: any[] = [];
const i = pipeAsync(
[11, 20, 33, 40, 55, 60, 77, 80, 99],
tap((value) => {
if (value % 2 === 0) {
throw new Error(`fail-${value}`); // throw for all even numbers
}
}),
retry(({attempt, index}) => {
retry(({attempt, error, index}) => {
att.push(attempt);
err.push(error);
ind.push(index);
return attempt < 1; // retry once
})
);
expect(await _asyncValues(i)).to.eql([11, 33, 55, 77, 99]);
expect(ind).to.eql([1, 3, 5, 7]);
expect(att).to.eql([0, 0, 0, 0]);
expect(err).to.eql([
new Error('fail-20'),
new Error('fail-40'),
new Error('fail-60'),
new Error('fail-80')
]);
expect(ind).to.eql([1, 3, 5, 7]);
});
};
14 changes: 11 additions & 3 deletions test/ops/retry/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,30 @@ export default () => {
});
it('must retry on callback result', () => {
const ind: number[] = [],
att: number[] = [];
att: number[] = [],
err: any[] = [];
const i = pipe(
[11, 20, 33, 40, 55, 60, 77, 80, 99],
tap((value) => {
if (value % 2 === 0) {
throw new Error(`fail-${value}`); // throw for all even numbers
}
}),
retry(({attempt, index}) => {
retry(({attempt, error, index}) => {
att.push(attempt);
err.push(error);
ind.push(index);
return attempt < 1; // retry once
})
);
expect([...i]).to.eql([11, 33, 55, 77, 99]);
expect(ind).to.eql([1, 3, 5, 7]);
expect(att).to.eql([0, 0, 0, 0]);
expect(err).to.eql([
new Error('fail-20'),
new Error('fail-40'),
new Error('fail-60'),
new Error('fail-80')
]);
expect(ind).to.eql([1, 3, 5, 7]);
});
};

0 comments on commit 46530e7

Please sign in to comment.