Skip to content

Commit

Permalink
Merge pull request #37 from pactumjs/expectjsonlength-enhancement
Browse files Browse the repository at this point in the history
feat: expectJsonLength enhancement docs
  • Loading branch information
leelaprasadv authored Sep 6, 2023
2 parents 0a70866 + 423645d commit 49fafab
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/api/assertions/expectJsonLength.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ Asserts on the length of JSON array objects.
```js
expectJsonLength(length)
expectJsonLength(path, length)
expectJsonLength(path, matcher) // Supports assertions with matcher functions
```

* Allowed matcher functions `lt`, `gt`, `lte`, `gte`, `notEquals` from `>=v3.5.1`

## Usage

### ✅ Correct Usage
Expand All @@ -26,6 +29,12 @@ await spec()
.expectJsonLength(1);
```

```js
const { lte } = require("pactum-matchers");
await spec()
.get('/api/users')
.expectJsonLength('data', lte(6));
```

```js
// bdd style
Expand All @@ -43,6 +52,10 @@ Expected json object length.

Json path. See [json-query](https://www.npmjs.com/package/json-query) for more usage details.

#### > matcher function (function)

Matcher function for comparison assertion - `lt`, `gt`, `lte`, `gte`, `notEquals`

## Examples

### Normal
Expand All @@ -63,4 +76,24 @@ const { spec } = require('pactum');
await spec()
.get('https://reqres.in/api/users')
.expectJsonLength('data', 6);
```

### Using Matcher Function

```js
const { spec } = require('pactum');
const { gte } = require("pactum-matchers");

await spec()
.get('https://jsonplaceholder.typicode.com/users')
.expectJsonLength('.', gte(10));
```

```js
const { spec } = require('pactum');
const { lte } = require("pactum-matchers");

await spec()
.get('https://reqres.in/api/users')
.expectJsonLength('data', lte(6));
```

0 comments on commit 49fafab

Please sign in to comment.