Created
February 22, 2020 22:50
-
-
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
This file contains 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
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