diff --git a/docs/api/requests/inspect.md b/docs/api/requests/inspect.md index d1de51eb..3edea244 100644 --- a/docs/api/requests/inspect.md +++ b/docs/api/requests/inspect.md @@ -18,10 +18,12 @@ Prints request & response details to the console. ```js inspect() -inspect('path') +inspect(path) +inspect(enable) ``` - `path` (**string**) - json path. *Visit [json-query](https://www.npmjs.com/package/json-query) for more usage details.* +- `enable` (**boolean**) - enable request & response printing. *Default: `true`* ## Usage @@ -38,4 +40,11 @@ await spec() .get('/api/users/1') .inspect('name') .inspect('age'); +``` + +```js +// disable inspection +await spec() + .get('/api/users/1') + .inspect(false); ``` \ No newline at end of file diff --git a/docs/api/requests/stores.md b/docs/api/requests/stores.md index 234a0ad9..e8ebee9c 100644 --- a/docs/api/requests/stores.md +++ b/docs/api/requests/stores.md @@ -5,8 +5,9 @@ ## Syntax ```js -stores(name, path); -stores(name, handler_name); +stores(name, path, options); +stores(name, handler_name, options); +stores(callback_function); ``` ## Usage @@ -65,6 +66,13 @@ Name of the capture handler to use. A custom function which should return an object to store the response value for pactum. +#### > options? (object) + +Options to pass to the handler. + +- `options.status?` - run the handler only on the given status. *Can be either 'PASSED' or 'FAILED'* +- `options.append?` - appends the stored data in an array. + ## Examples ### Store single value @@ -122,6 +130,33 @@ await spec() .expectStatus(200); ``` +### Store value when request fails + +```js +const { spec } = require('pactum'); + +await spec() + .get('http://jsonplaceholder.typicode.com/posts') + .expectStatus(200) + .stores('FirstPostId', '[0].id', { status: 'FAILED' }); +``` + +### Append value to the store + +```js +const { spec } = require('pactum'); + +await spec() + .get('http://jsonplaceholder.typicode.com/posts/1') + .expectStatus(200) + .stores('UserIds', 'id', { append: true }); + +await spec() + .get('http://jsonplaceholder.typicode.com/posts/2') + .expectStatus(200) + .stores('UserIds', 'id', { append: true }); +``` + ## See Also - [Integration Testing](/guides/integration-testing)