Skip to content

Commit

Permalink
chore: store options
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep committed Oct 26, 2024
1 parent 5e17ff5 commit 8e5a04a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
11 changes: 10 additions & 1 deletion docs/api/requests/inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
```
39 changes: 37 additions & 2 deletions docs/api/requests/stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8e5a04a

Please sign in to comment.