Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support matching query params for post, put methods. #130

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ axios.get('/users', { params: { searchText: 'John' } } )
});
```

For `GET`, `DELETE`, `HEAD` and `OPTIONS` methods, the second argument coresponds to the expected params. For `PUT`, `POST` and `PATCH` methods, this argument coresponds to the expected request body. To match params for these methods, pass the expected params as the fouth argument, and ignore headers with `undefined`.

```js
// match body and params
mock.onPut('/product', { name: 'foo' }, undefined, { id: 4 }).reply(204);
axios.put('/product', { name: 'foo' }, { params: { id: 4 } }).then(console.log)
// match params only, for onPut, onPost, onPatch
mock.onPost('/product', undefined , undefined, { id: 4 }).reply(204);
axios.post('/product', undefined , { params: { id: 4 } }).then(console.log)
// does not match
mock.onPut('/product', { name: 'foo' }, undefined, { id: 4 }).reply(204);
axios.put('/product', { name: 'wrong' }, { params: { id: 4 } }).then(console.log)
// does not match
mock.onPut('/product', { name: 'foo' }, undefined, { id: 4 }).reply(204);
axios.put('/product', { name: 'foo' }, { params: { id: 999 } }).then(console.log)
```

To add a delay to responses, specify a delay amount (in milliseconds) when instantiating the adapter

```js
Expand Down Expand Up @@ -195,6 +212,14 @@ Mocking a request with a specific request body/data
mock.onPut('/product', { id: 4, name: 'foo' }).reply(204);
```

Mocking a request with a specific request body/data and parameters

Make sure to pass `undefined` as a expected headers, in the third argument

```js
mock.onPut('/product', { name: 'foo' }, undefined, { id: 4 }).reply(204);
```

`.passThrough()` forwards the matched request over network

```js
Expand Down
Loading