Created
November 26, 2019 02:47
-
-
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)
This file contains hidden or 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
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