Created
December 5, 2024 14:57
-
-
Save devotdev/c2632ff31bdd8431853d57396f49381c to your computer and use it in GitHub Desktop.
Using beforeEach with asynchronous code
This file contains 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
describe('Async API Tests', () => { | |
let mockUser; | |
// Example using beforeEach to set up async state before each test | |
beforeEach(async () => { | |
mockUser = { id: 1, name: 'Jane Doe' }; | |
axios.get.mockResolvedValue({ data: mockUser }); | |
}); | |
it('fetches user asynchronously', async () => { | |
const result = await fetchData('https://api.example.com/user/1'); | |
expect(result).toEqual(mockUser); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment