Last active
August 15, 2022 18:26
-
-
Save MauricioRobayo/ac82411721eca226eac70879d344b392 to your computer and use it in GitHub Desktop.
Testing Asynchronous Code
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
| test('the data is peanut butter', async () => { | |
| const data = await fetchData(); | |
| expect(data).toBe('peanut butter'); | |
| }); | |
| test('the fetch fails with an error', async () => { | |
| expect.assertions(1); | |
| try { | |
| await fetchData(); | |
| } catch (e) { | |
| expect(e).toMatch('error'); | |
| } | |
| }); | |
| test('the data is peanut butter', async () => { | |
| await expect(fetchData()).resolves.toBe('peanut butter'); | |
| }); | |
| test('the fetch fails with an error', async () => { | |
| await expect(fetchData()).rejects.toMatch('error'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment