Created
November 3, 2018 10:36
-
-
Save InfoSec812/71aca7cc7a452a5d3c7b4292b61dea28 to your computer and use it in GitHub Desktop.
Mocked Axios Method Using Jest
This file contains hidden or 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
axios.get = jest.fn((path, options) => { | |
expect(path).toEqual('/api/v1/user'); | |
expect(options.username).toEqual(USERNAME); | |
expect(options.password).toEqual(PASSWORD); | |
let response = { | |
// 'data' is the response that was provided by the server | |
data: TOKEN, | |
// 'status' is the HTTP status code from the server response | |
status: 200, | |
// 'statusText' is the HTTP status message from the server response | |
statusText: 'OK' | |
}; | |
return Promise.resolve(response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment