File tree 1 file changed +2
-11
lines changed
1 file changed +2
-11
lines changed Original file line number Diff line number Diff line change @@ -2,29 +2,20 @@ import axios from "axios"
2
2
import { getApiKey , login , logout } from "./api"
3
3
import * as TypesGen from "./typesGenerated"
4
4
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
-
11
5
describe ( "api.ts" , ( ) => {
12
6
describe ( "login" , ( ) => {
13
7
it ( "should return LoginResponse" , async ( ) => {
14
8
// given
15
9
const loginResponse : TypesGen . LoginWithPasswordResponse = {
16
10
session_token : "abc_123_test" ,
17
11
}
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 } )
22
13
23
14
// when
24
15
const result = await login ( "test" , "123" )
25
16
26
17
// then
27
- expect ( axiosMockPost ) . toHaveBeenCalled ( )
18
+ expect ( axios . post ) . toHaveBeenCalled ( )
28
19
expect ( result ) . toStrictEqual ( loginResponse )
29
20
} )
30
21
You can’t perform that action at this time.
0 commit comments