Skip to content

Instantly share code, notes, and snippets.

@francisbrito
Created September 29, 2016 18:18
Show Gist options
  • Save francisbrito/ca05c99e484887c1543fb31d3ce0fd61 to your computer and use it in GitHub Desktop.
Save francisbrito/ca05c99e484887c1543fb31d3ce0fd61 to your computer and use it in GitHub Desktop.
describe('My suite', () => {
it('works with promises', done => {
multiplyAsync(4, 5)
.then(r => expect(r).toBe(20))
.then(done);
});
it('works even if promises reject', done => {
divideAsync(2, 0)
.catch(e => expect(e.message).toBe('Attempted to divide by zero'))
.then(done);
});
});
function multiplyAsync(x, y) {
return Promise.resolve(x * y);
}
function divideAsync(x, y) {
if (y === 0) return Promise.reject(new Error('Attempted to divide by zero'));
return Promise.resolve(x / y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment