Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ondrej-kvasnovsky/10213c32a50c2bcf8d6a3612adc0524e to your computer and use it in GitHub Desktop.
Save ondrej-kvasnovsky/10213c32a50c2bcf8d6a3612adc0524e to your computer and use it in GitHub Desktop.
How to test successful promise and rejected when a promis fails (async await)
async function doSomething() {
return 'some result'
}
async function doSomethingAndFail() {
throw new Error()
}
describe('promise testing', () => {
it('resolves fine', async () => {
await expect(doSomething()).resolves.toBeDefined();
});
it('fails and thus rejects', async () => {
await expect(doSomethingAndFail()).rejects.toThrow(Error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment