File tree Expand file tree Collapse file tree 1 file changed +2
-11
lines changed
Expand file tree Collapse file tree 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"
22import { getApiKey , login , logout } from "./api"
33import * 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-
115describe ( "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
You can’t perform that action at this time.
0 commit comments