Skip to content

Instantly share code, notes, and snippets.

@darde
Created February 22, 2020 22:50
Show Gist options
  • Save darde/2eff2a5f46d8db036acdde205ef85352 to your computer and use it in GitHub Desktop.
Save darde/2eff2a5f46d8db036acdde205ef85352 to your computer and use it in GitHub Desktop.
Medium store - Testing asynchronous code with Jest and Testing Library React - src/services/fetchPosts.test.js
import fetchPosts from './fetchPosts';
import mockedAxios from 'axios';
describe('fetchPosts', () => {
it('fetch the posts', async () => {
const posts = await fetchPosts();
const expectedResponse = [
{
id: 1,
title: 'This is a tech post',
},
{
id: 2,
title: 'Post about testing code',
},
];
expect(posts).toEqual(expectedResponse);
expect(mockedAxios.get).toHaveBeenCalledTimes(1);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment