Skip to content

Commit

Permalink
testing added
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Aug 2, 2024
1 parent 22cd432 commit 3bc7220
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/ops/retry/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sync from './sync';
import async from './async';

describe('retry', () => {
describe('sync', sync);
describe('async', async);
});
51 changes: 50 additions & 1 deletion test/ops/retry/sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
import {expect} from '../../header';
import {pipe, retry} from '../../../src';
import {pipe, retry, tap} from '../../../src';

export default () => {
it('must not retry on 0 attempts', () => {
let count = 0;
const i = pipe(
[1, 2, 3],
tap(() => {
if (!count++) {
throw 'ops!'; // throw only once
}
}),
retry(0)
);
expect(() => {
[...i];
}).to.throw('ops!');
});
it('must retry the number of attempts', () => {
let count = 0;
const i = pipe(
[1, 2, 3],
tap(() => {
if (!count++) {
throw 'ops!'; // throw only once
}
}),
retry(1)
);
expect([...i]).to.eql([2, 3]);
});
it('must retry on callback result', () => {
let count = 0;
const indexes: Array<number> = [],
attempts: Array<number> = [];
const i = pipe(
[1, 2, 3, 4, 5],
tap(() => {
if (count++ < 3) {
throw 'ops!'; // throw 3 times
}
}),
retry((idx, att) => {
indexes.push(idx);
attempts.push(att);
return true;
})
);
expect([...i]).to.eql([4, 5]);
expect(indexes).to.eql([0, 0, 0]);
expect(attempts).to.eql([0, 1, 2]);
});
};

0 comments on commit 3bc7220

Please sign in to comment.