Skip to content

Commit

Permalink
Readme: add example for advanced responses
Browse files Browse the repository at this point in the history
  • Loading branch information
phlmn committed Jun 8, 2018
1 parent 82182f6 commit 94217c7
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,40 @@ test('test response', () => {
data: 'some data'
});

return fetch('/path/to/nowhere', {
body: JSON.stringify({
data: 'I am a body'
})
}).then(response => {
return fetch('/path/to/nowhere').then(response => {
return response.json();
}).then(body => {
expect(body.data).toBe('some data');
});
});
```


### Advanced response

You can set some parameters of the response with the third argument of `mockResponse(…)`.

```javascript
import hungryFetch from 'hungry-fetch';

test('advanced response', () => {
hungryFetch.mockResponse('/somewhere', {}, {
// set custom status code
status: 204,

// set custom content type
contentType: 'plain/text',

// set additional headers
headers: {
'X-MyHeader': 'hello',
},
});

return fetch('/somewhere').then(res => {
expect(res.status).toBe(204);
expect(res.headers.get('Content-Type')).toBe('plain/text');
expect(res.headers.get('X-MyHeader')).toBe('hello');
});
});
```

0 comments on commit 94217c7

Please sign in to comment.