|
5 | 5 | ## Syntax |
6 | 6 |
|
7 | 7 | ```js |
8 | | -stores(name, path); |
9 | | -stores(name, handler_name); |
| 8 | +stores(name, path, options); |
| 9 | +stores(name, handler_name, options); |
| 10 | +stores(callback_function); |
10 | 11 | ``` |
11 | 12 |
|
12 | 13 | ## Usage |
@@ -65,6 +66,13 @@ Name of the capture handler to use. |
65 | 66 |
|
66 | 67 | A custom function which should return an object to store the response value for pactum. |
67 | 68 |
|
| 69 | +#### > options? (object) |
| 70 | + |
| 71 | +Options to pass to the handler. |
| 72 | + |
| 73 | +- `options.status?` - run the handler only on the given status. *Can be either 'PASSED' or 'FAILED'* |
| 74 | +- `options.append?` - appends the stored data in an array. |
| 75 | + |
68 | 76 | ## Examples |
69 | 77 |
|
70 | 78 | ### Store single value |
@@ -122,6 +130,33 @@ await spec() |
122 | 130 | .expectStatus(200); |
123 | 131 | ``` |
124 | 132 |
|
| 133 | +### Store value when request fails |
| 134 | + |
| 135 | +```js |
| 136 | +const { spec } = require('pactum'); |
| 137 | + |
| 138 | +await spec() |
| 139 | + .get('http://jsonplaceholder.typicode.com/posts') |
| 140 | + .expectStatus(200) |
| 141 | + .stores('FirstPostId', '[0].id', { status: 'FAILED' }); |
| 142 | +``` |
| 143 | + |
| 144 | +### Append value to the store |
| 145 | + |
| 146 | +```js |
| 147 | +const { spec } = require('pactum'); |
| 148 | + |
| 149 | +await spec() |
| 150 | + .get('http://jsonplaceholder.typicode.com/posts/1') |
| 151 | + .expectStatus(200) |
| 152 | + .stores('UserIds', 'id', { append: true }); |
| 153 | + |
| 154 | +await spec() |
| 155 | + .get('http://jsonplaceholder.typicode.com/posts/2') |
| 156 | + .expectStatus(200) |
| 157 | + .stores('UserIds', 'id', { append: true }); |
| 158 | +``` |
| 159 | + |
125 | 160 | ## See Also |
126 | 161 |
|
127 | 162 | - [Integration Testing](/guides/integration-testing) |
|
0 commit comments