Skip to content

Commit 8e5a04a

Browse files
committed
chore: store options
1 parent 5e17ff5 commit 8e5a04a

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

docs/api/requests/inspect.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ Prints request & response details to the console.
1818

1919
```js
2020
inspect()
21-
inspect('path')
21+
inspect(path)
22+
inspect(enable)
2223
```
2324

2425
- `path` (**string**) - json path. *Visit [json-query](https://www.npmjs.com/package/json-query) for more usage details.*
26+
- `enable` (**boolean**) - enable request & response printing. *Default: `true`*
2527

2628
## Usage
2729

@@ -38,4 +40,11 @@ await spec()
3840
.get('/api/users/1')
3941
.inspect('name')
4042
.inspect('age');
43+
```
44+
45+
```js
46+
// disable inspection
47+
await spec()
48+
.get('/api/users/1')
49+
.inspect(false);
4150
```

docs/api/requests/stores.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
## Syntax
66

77
```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);
1011
```
1112

1213
## Usage
@@ -65,6 +66,13 @@ Name of the capture handler to use.
6566

6667
A custom function which should return an object to store the response value for pactum.
6768

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+
6876
## Examples
6977

7078
### Store single value
@@ -122,6 +130,33 @@ await spec()
122130
.expectStatus(200);
123131
```
124132

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+
125160
## See Also
126161

127162
- [Integration Testing](/guides/integration-testing)

0 commit comments

Comments
 (0)