jefflau/jest-fetch-mock

[Feature request] Support vitest

IanVS opened this issue · 2 comments

IanVS commented

Hi there. I've been using jest-fetch-mock successfully for a while, but am moving from jest to vitest, and would love to continue using jest-fetch-mock. It seems like it would be a simple matter of using vi instead of jest, and in fact I've hacked that into my node_modules with good success.

I propose adding a createMocker function, or similar, which would accept an argument of either jest or vi, (defaulting to jest perhaps), and would return fetch using that tool. I think this can be done in a non-breaking way, by continuing to export the default as createMocker(jest).

What do you think? Would you be open to a PR exploring this possibility, or do you consider it to be out-of-scope, in which case I'll be happy to fork and create a vitest-specific version.

Thanks for your consideration.

IanVS commented

Hmmmm, it might be tricker thank I thought to keep backwards compatibility, due to enableFetchMocks and disableFetchMocks being exported like they are. But maybe there's still a way to do it? I'm no esm/cjs compat expert by any means.

IanVS commented

After I played around with it a bit more, it seemed like a bigger challenge to support both jest and vitest, so I ended up creating a fork. https://www.npmjs.com/package/vitest-fetch-mock.

Thanks for all your hard work on this library!