A fetch mock library for React Native, v1.0.0. Allows developers to define mock responses for API endpoints using patterns and Mock.js integration. Supports delayed responses, proxy to real servers, fallback to network, and exclusion of certain paths. Useful for testing and development without a backend. Alternatives like fetch-mock exist, but this is tailored for React Native's fetch implementation and offers inline mocking via a mock directory with flexible configuration. No recent updates; considered stable for its feature set.
npm install react-native-fetch-mockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up mock API endpoints for GET and POST, initializes FetchMock with options, and assigns it to global.fetch.
Use global.fetch = new FetchMock(mocks, options).fetch;
Return { status: 201, body: ... } or { status: 204 } for non-200 responses.Ensure your mock file uses export default { ... };Pass { delay: 2000 } as second argument to fetch() for a per-call delay.Ensure you pass options.fetch: global.fetch to the constructor.
Replace with process.env.NODE_ENV !== 'production' or use a babel transform.
Add import Mock from 'mockjs' at the top of your mock file.
Run npm install mockjs --save-dev