Skip to content

Instantly share code, notes, and snippets.

@kozo002
Created May 27, 2020 03:31
Show Gist options
  • Save kozo002/e74fbe2d3f65c2c18a3307f2e57bbb89 to your computer and use it in GitHub Desktop.
Save kozo002/e74fbe2d3f65c2c18a3307f2e57bbb89 to your computer and use it in GitHub Desktop.
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