Skip to content

Instantly share code, notes, and snippets.

@pushkar100
Created June 24, 2022 22:20
Show Gist options
  • Save pushkar100/e80f3f385989d80e4803c4c6bd58f16a to your computer and use it in GitHub Desktop.
Save pushkar100/e80f3f385989d80e4803c4c6bd58f16a 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', (done) => {
// Arrange
const testRequest = { animal: true };
// Act
fetchFakeAPIData(testRequest).then(({ animal, name }) => {
// Assert
expect(animal).toBe('Dog');
expect(name).toBe('Charlie');
done();
})
});
test('fetchFakeAPIData, when not requesting an animal, responds with an error message', (done) => {
// Arrange
const testRequest = { random: true };
// Act
fetchFakeAPIData(testRequest).catch(({ error }) => {
// Assert
expect(error).toMatch(/Did not find species/i);
done();
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment