Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Use sinon for mocking axios #57

Open
hdurix opened this issue Nov 23, 2018 · 0 comments
Open

Use sinon for mocking axios #57

hdurix opened this issue Nov 23, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@hdurix
Copy link
Member

hdurix commented Nov 23, 2018

I think we should sinon rather than jest for mocking axios in unit tests.

It's really hard to mock properly axios with the couple Jest & TypeScript. For now, we have something like:

import axios from 'axios';

const mockedAxios: any = axios;

jest.mock('axios', () => ({
  get: jest.fn(),
  put: jest.fn()
}));

mockedAxios.get.mockReturnValue(Promise.resolve({}));

But as it's cast as any, it's not really TypeScript friendly...

It's how it is done in react tests: https://github.com/jhipster/generator-jhipster/blob/master/generators/client/templates/react/src/test/javascript/spec/app/shared/reducers/application-profile.spec.ts.ejs#L79.

@hdurix hdurix added the enhancement New feature or request label Jan 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant