Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Created June 24, 2022 22:05
Show Gist options
  • Save pushkar100/09a16290da1c3d2f4d6fdc06cb3b800c to your computer and use it in GitHub Desktop.
Save pushkar100/09a16290da1c3d2f4d6fdc06cb3b800c to your computer and use it in GitHub Desktop.
/* 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