Skip to content

Instantly share code, notes, and snippets.

@InfoSec812
Created November 3, 2018 10:36
Show Gist options
  • Save InfoSec812/71aca7cc7a452a5d3c7b4292b61dea28 to your computer and use it in GitHub Desktop.
Save InfoSec812/71aca7cc7a452a5d3c7b4292b61dea28 to your computer and use it in GitHub Desktop.
Mocked Axios Method Using Jest
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