jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
883 stars 116 forks source link

Add default export type #147

Closed joshuajaco closed 4 years ago

joshuajaco commented 4 years ago

Closes https://github.com/jefflau/jest-fetch-mock/issues/146

yinzara commented 4 years ago

I started to write another comment, however I think your concerns are valid. A library that does not have any form of exported contents that only supplies types and a global scope can be confusing and difficult for others to understand. There is also no way with the current library to say "Only mock for this one test".

The change you've suggested isn't actually enough to achieve what needs to be done to fix the library. I'm going to open a new PR with additional changes that should alleviate this confusion.

yinzara commented 4 years ago

Moved to PR#148

joshuajaco commented 4 years ago

This PR was just meant to type the already existing default export, because we are currently globally mocking fetch with:

require('jest-fetch-mock').enableMocks();

and then using it in our tests with:

const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
customGlobal.fetch.mockResponse('{}');

Which isn't ideal. I applied the changes of this PR locally and it seemed to work in our setup. However I can see a "Only mock for this one test" feature being useful as well. Thanks for the help 👍