vi-fetch
Easiest way to mock fetch
Compatible with Vitest and Jest when using ESM flag or with transform for /node_modules/vi-fetch
.
The main difference with fetch-mock or fetch-mock-jest is that they consider fetch
just as a function call instead of calls to endpoints. vi-fetch
provides matchers to test calls to endpoints instead of simply function calls.
For example, we consider an endpoint to be a part of URL until the first ?
: query is an argument to an endpoint, just like body
, - that's why we provide matchers like toHaveFetchedWithQuery
and toHaveFetchedWithBody
.
Docs
Read full docs on GitHub.