Skip to main content

fetch-mock@12

ยท 2 min read
fetch-mock maintainer

A couple of months ago I wrote about @fetch-mock/core, intended to be a library not menat for direct use by users, but instead wrapped by libraries that implemented APIs more idiomatic for use alongside frameworks such as jest or vitest.

But while implementing @fetch-mock/jest and @fetch-mock/vitest, I relaised something: the clashes between jest and fetch-mock-jest (the wrapper I wrote a few years ago for fetch-mock) were largely due to a) bad decisions about the design of fetch-mock-jest, which I can back away from b) parts of the fetch-mock API which ahd previously imitated mocha's API naming conventions

By removing those two flaws, in principle there's nothing impossible about having a library that both has a good, user-friendly public API intended for direct use and that lends itself to being wrapped for idiomatic use alongside a testing framework.

So while writing @fetch-mock/jest and @fetch-mock/vitest, I have also added a few methods to @fetch-mock/core that make it easier for direct use, and will soon rename it to fetch-mock, publishing it as version 12. While these API additions are more user friendly than the previous low-level API, it's still fairly sparse. Please raise an issue if you think any methods should be added.

To make it easier to migrate from fetch-mock@11 and below I've been working on a new @fetch-mock/codemods library. If you'd like to try it out to migrate from fetch-mock to @fetch-mock/core, I'd be grateful of the feedback.

It'll take a little while to restructure the documentation and build pipeline, but hopefully the new fetch-mock will be released in October.