Requirements
fetch-mock requires the following to run:
For usage in older versions of Node.js or older browsers consider using an older version of fetch-mock.
If using node-fetch in your application fetch-mock@12 and above may work for you, but the fetch-mock test suite does not run against node-fetch, so it may be safer to use an older version of fetch-mock that is tested against node-fetch and is less likely to introduce breaking changes.
Usage with react-native
As react-native ships with a non-spec-compliant version of the URL and URLSearchParams classes, fetch-mock will not run in a react-native environment unless you also include react-native-url-polyfill. You can either:
- Include it in your application code. This will add approx 11kb of gzipped code to your bundle.
- Include it in your test files only. If doing this, its recommended that you have some integration tests that don't use fetch-mock in order to avoid inserting behaviour into your application that relies on the polyfill.