Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Last active June 24, 2022 21:51
Show Gist options
  • Save pushkar100/9b7a6482e3af0a4176c8b6e01a4b26e5 to your computer and use it in GitHub Desktop.
Save pushkar100/9b7a6482e3af0a4176c8b6e01a4b26e5 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', () => {
// Arrange
const testRequest = { animal: true };
// Act
return fetchFakeAPIData(testRequest).then(({ animal, name }) => {
// Assert
expect(animal).toBe('Dog');
expect(name).toBe('Charlie');
})
});
test('fetchFakeAPIData, when not requesting an animal, responds with an error message', () => {
// Arrange
const testRequest = { random: true };
// Act
return 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