Created
May 27, 2020 03:31
-
-
Save kozo002/e74fbe2d3f65c2c18a3307f2e57bbb89 to your computer and use it in GitHub Desktop.
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
async function getUser(httpClient: HttpClient, userId: number): Promise<User> { | |
const res = await httpClient.get(`/api/users/${userId}`) | |
return res.data.user | |
} | |
describe('when the API ends in successful', () => { | |
it('returns the user data', async () => { | |
const get = jest.fn(() => { | |
return Promise.resolve({ | |
data: { | |
user: { | |
id: 1, | |
name: 'zochang' | |
} | |
} | |
}) | |
}) | |
const dummyHttpClient = { get } | |
const user = await getUser(dummyHttpClient, 1) | |
expect(get).toHaveBeenCalledWith('/api/users/1') | |
expect(user.name).toEqual('zochang') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment