Created
June 24, 2022 22:05
-
-
Save pushkar100/09a16290da1c3d2f4d6fdc06cb3b800c to your computer and use it in GitHub Desktop.
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
/* src/__tests__/helpers/index.test.js */ | |
import { isEarlierThanNow, fetchFakeAPIData } from '../../helpers'; | |
//... | |
test('fetchFakeAPIData, when requesting an animal, responds with a dog', async () => { | |
// Arrange | |
const testRequest = { animal: true }; | |
// Act | |
const { animal, name } = await fetchFakeAPIData(testRequest); | |
// Assert | |
expect(animal).toBe('Dog'); | |
expect(name).toBe('Charlie'); | |
}); | |
test('fetchFakeAPIData, when not requesting an animal, responds with an error message', async () => { | |
// Arrange | |
const testRequest = { random: true }; | |
// Act | |
try { | |
await fetchFakeAPIData(testRequest); | |
} catch ({ error }) { | |
// Assert | |
expect(error).toMatch(/Did not find species/i); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment