Last active
January 5, 2017 07:53
-
-
Save robinpokorny/fb01d868d79e9afadff5d5ddcfa48f08 to your computer and use it in GitHub Desktop.
Boilerplate for promise fallback kata (for Medium article)
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
const firstResult = (services) => { /* … */ } | |
firstResult([ | |
() => Promise.resolve([]), | |
() => Promise.resolve(['Berlin']), | |
() => console.error('Do not call me!') | |
]) | |
.then((result) => | |
console.assert(result[0] === 'Berlin', 'Test1 failed!') | |
) | |
firstResult([ | |
() => Promise.resolve([]), | |
() => Promise.resolve([]) | |
]) | |
.then((result) => | |
console.assert(result.length === 0, 'Test2 failed!') | |
) | |
firstResult([]) | |
.then((result) => | |
console.assert(result.length === 0, 'Test3 failed!') | |
) | |
firstResult([ | |
() => Promise.reject('timeout'), | |
() => Promise.resolve(['Berlin']) | |
]) | |
.then(() => console.error('Should be rejected!')) | |
.catch((reason) => | |
console.assert(reason === 'timeout', 'Test4 failed!') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment