Skip to content

Commit

Permalink
create,tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrosSacASac committed Dec 21, 2020
1 parent eee96a7 commit 5e780fa
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/specification/chainPromiseNTimes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import test from "ava";
import { chainPromiseNTimes } from "../../utility.js";


const resolveValue = {};
const promiseCreator = () => {
return Promise.resolve(resolveValue);
};
const rejectValue = `error`;
const rejectingPromiseCreator = () => {
return Promise.reject(rejectValue);
};

test(`chainPromiseNTimes returns a promise`, t => {
t.is(typeof chainPromiseNTimes(promiseCreator, 1).then, `function`);
});

test(`chainPromiseNTimes resolves with values Array`, async t => {
return chainPromiseNTimes(promiseCreator, 2).then(values => {
t.truthy(Array.isArray(values));
values.forEach(value => {
t.is(value, resolveValue);
});
});
});

test(`chainPromiseNTimes reject with first rejecting value`, async t => {
return chainPromiseNTimes(rejectingPromiseCreator, 3).then(() => {
}).catch(error => {
t.is(error, rejectValue);
});
});

0 comments on commit 5e780fa

Please sign in to comment.