Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae42dcc

Browse files
committed
Fix API test
1 parent 1b6b297 commit ae42dcc

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

site/src/api/api.test.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,20 @@ import axios from "axios"
22
import { getApiKey, login, logout } from "./api"
33
import * as TypesGen from "./typesGenerated"
44

5-
// Mock the axios module so that no real network requests are made, but rather
6-
// we swap in a resolved or rejected value
7-
//
8-
// See: https://jestjs.io/docs/mock-functions#mocking-modules
9-
jest.mock("axios")
10-
115
describe("api.ts", () => {
126
describe("login", () => {
137
it("should return LoginResponse", async () => {
148
// given
159
const loginResponse: TypesGen.LoginWithPasswordResponse = {
1610
session_token: "abc_123_test",
1711
}
18-
const axiosMockPost = jest.fn().mockImplementationOnce(() => {
19-
return Promise.resolve({ data: loginResponse })
20-
})
21-
axios.post = axiosMockPost
12+
jest.spyOn(axios, "post").mockResolvedValueOnce({ data: loginResponse })
2213

2314
// when
2415
const result = await login("test", "123")
2516

2617
// then
27-
expect(axiosMockPost).toHaveBeenCalled()
18+
expect(axios.post).toHaveBeenCalled()
2819
expect(result).toStrictEqual(loginResponse)
2920
})
3021

0 commit comments

Comments
 (0)