Created
July 6, 2021 06:19
-
-
Save manoj-mass/1285c363c51921a2c1bb96b3bf90b0fe to your computer and use it in GitHub Desktop.
ShowTitle api mock - https://medium.com/@manojdarshana/reactjs-testing-with-jest-81bb17dd6c65
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 { render, screen } from '@testing-library/react'; | |
import axios from 'axios'; | |
import { getPost } from '../apis/Posts'; | |
describe('test post app', () => { | |
it('check get post', () => { | |
jest.mock('axios'); | |
axios.get = jest.fn(); | |
const postResponse = { | |
"userId": 1, | |
"id": 1, | |
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", | |
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" | |
} | |
const resp = { data: postResponse }; | |
axios.get.mockResolvedValue(resp); | |
return getPost().then(data => expect(data.title).toEqual("sunt aut facere repellat provident occaecati excepturi optio reprehenderit")) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment