jefflau / jest-fetch-mock

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

jest config compatibility #190

Closed darkship closed 3 years ago

darkship commented 3 years ago

Hey, in my jest config I have

restoreMocks: true,
clearMocks: true,
resetMocks: true,

Does jest-fetch-mock follow this rules and does it really clean up the mock?

I had a broken test because some mock data was an empty string instead of an object

FetchError: invalid json response body at  reason: Unexpected end of JSON input

    at /home/user/node_modules/node-fetch/lib/index.js:272:32

and the underlying tests became all broken saying that the data was missing.

yinzara commented 3 years ago

No, there's no way for us to hook into that as we actually overwrite the global fetch with our mocked version. You'll need to reset or restore the mock as appropriate using functions in jest-fetch-mock in an "afterAll" or "afterEach"

darkship commented 3 years ago

Thanks for your answer