https://github.com/fiverr/react-fetch-mock-provider
Mock HTTP requests made using fetch from your React component
https://github.com/fiverr/react-fetch-mock-provider
fetch http mock react
Last synced: 5 months ago
JSON representation
Mock HTTP requests made using fetch from your React component
- Host: GitHub
- URL: https://github.com/fiverr/react-fetch-mock-provider
- Owner: fiverr
- Created: 2018-11-28T07:49:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-21T22:47:28.000Z (over 3 years ago)
- Last Synced: 2025-10-04T17:51:10.343Z (9 months ago)
- Topics: fetch, http, mock, react
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@fiverr/react-fetch-mock-provider
- Size: 6.84 KB
- Stars: 2
- Watchers: 50
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-fetch-mock-provider
A "Reactified" wrapper around [`fetch-mock`](https://github.com/wheresrhys/fetch-mock), that provides a more React-friendly interface.
This component allows you to easily mock HTTP requests made with `fetch`.
## Installation
```
npm install -D @fiverr/react-fetch-mock-provider
```
## Usage
### Basic mocking
```js
import FetchMockProvider from '@fiverr/react-fetch-mock-provider';
```
### Using a Function for `response`
Same as in `fetch-mock`, the `response` prop can be a function.
See the full documentation [here](http://www.wheresrhys.co.uk/fetch-mock/#api-mockingmock_response).
```js
import FetchMockProvider from '@fiverr/react-fetch-mock-provider';
{
const status = payload.body.someRequiredParameter ? 200 : 500;
return {
body: {},
status
};
}}]}>
```