-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eee96a7
commit 5e780fa
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |