An open API service indexing awesome lists of open source software.

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

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
};
}}]}>

```