Skip to content

Instantly share code, notes, and snippets.

@robinpokorny
Last active January 5, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinpokorny/fb01d868d79e9afadff5d5ddcfa48f08 to your computer and use it in GitHub Desktop.
Save robinpokorny/fb01d868d79e9afadff5d5ddcfa48f08 to your computer and use it in GitHub Desktop.
Boilerplate for promise fallback kata (for Medium article)
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