jefflau / jest-fetch-mock

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

Fix global `resetMock: true` breaking fetch mocks #197

Closed ishmaelthedestroyer closed 3 years ago

ishmaelthedestroyer commented 3 years ago

Overview When developers set resetMock to true in their jest.config.js, it breaks the automocking. This can be seen by errors surfacing saying isMocking is not a function or its return value is not iterable or related.

This fixes that issue by resetting the isMocking and global fetch functions by resetting their values in a beforeEach call.

yinzara commented 3 years ago

While I appreciate the work you've done on this PR, calling "beforeEach" in a dependent library (i.e. this library) is not something I'd be ok with. That would break in many ways you probably aren't foreseeing as any test that has a "beforeEach" outside of a describe block would have its beforeEach overwritten (or would override the one you added) by your code.

If you wanted to submit a PR that provided the beforeEach function implementation and updated the readme with instructions how to use it, I'd consider it.