Assign to window.fetch to create a wrapper over the Fetch API, if mockData are supplied it will fake the call to your API and return a response with fake data: window.fetch = Fetch({url:{...data}})
npm install igsem-mock-fetch-api##Mocking Fetch API
Simple wrapper around Fetch API, it accepts a json object of urls mapped to mock response data.
If the url is called with standard fetch, it will return the mock data without hitting your backend.
This way you can easily start developing your frontend and create a json tree of fake data to implement
for your backend without the need of a REST API. Check the test files for examples.
!Note: query params are ignored eg www.url.tld?search=whatever will be resolved to www.url.tld and return standard data.
```
use_mock_api && window.fetch = Fetch(mockdata);
Another advantage is that in the mockData you will build up exactly the structure you require and you just pass it to the BE team..I need this :)
``
// simulate 3 second latency
window.mock_fetch_timeout = 3000;`$3
`
yarn add igsem-mock-fetch-api
npm i --save-dev igsem-mock-fetch-api`
$3
In your index.js file just import the script and assign it to the global window passing in the mock data
import Fetch from 'igsem-mock-fetch-api';
window.fetch = Fetch(mockdata);
``
example of mockData:``
const mockData =
{
'http://test.com': {
'body': "some text",
'status_code': 201
},
'http://test2.com': {
'body': "some text"
},
'http://test3.com': {
'body': "some text",
'status_code': 404
}
};