Skip to content

Commit 904d5dc

Browse files
committed
Added function to check non-unique array element in response.
1 parent 27b9f84 commit 904d5dc

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ Expects HTTP response to return an empty JSON collection.
338338
Expects HTTP response to return a JSON collection with a single element.
339339
* [`utils.expect.response.not.empty`](#utilsexpectresponsenotempty):
340340
Expects HTTP response to return a non-empty JSON collection.
341+
* [`utils.expect.response.not.unique`](#utilsexpectresponsenotunique):
342+
Expects HTTP response to return a JSON collection with two or more items.
341343

342344
### `utils.expect.response.text`
343345
Expects HTTP response to return a simple (not the JSON) data type, such as string.
@@ -385,8 +387,9 @@ utils.expect.response.one(pm);
385387
Expects HTTP response to return a JSON collection (can be empty or contain the specified minimum and/or maximum number of items). The `utils.expect.response.many` function can be called via one of these shortcuts:
386388

387389
* [`utils.expect.response.empty`](#utilsexpectresponseempty) to check for an empty collection
388-
* [`utils.expect.response.not.empty`](#utilsexpectresponsenotempty) to check for a non-empty collection
389390
* [`utils.expect.response.unique`](#utilsexpectresponseunique) to check for a collection with a single (unique) item
391+
* [`utils.expect.response.not.empty`](#utilsexpectresponsenotempty) to check for a non-empty collection
392+
* [`utils.expect.response.not.unique`](#utilsexpectresponsenotunique) to check for a collection with multiple items
390393

391394
#### Prototype
392395
```JavaScript
@@ -448,6 +451,20 @@ Check if the HTTP response data contains a JSON collection with at least one ite
448451
utils.expect.response.not.empty(pm);
449452
```
450453

454+
### `utils.expect.response.not.unique`
455+
Expects HTTP response to return a JSON collection with at least two items.
456+
457+
#### Prototype
458+
```JavaScript
459+
utils.expect.response.not.unique(pm)
460+
```
461+
462+
#### Example
463+
Check if the HTTP response data contains a JSON collection with at least two items.
464+
```JavaScript
465+
utils.expect.response.not.unique(pm);
466+
```
467+
451468
## Property validation functions
452469
Property validation functions check named properties of the specified objects. The primary benefits of these functions (compared to the underlying [Chai assertions](https://www.chaijs.com/api/bdd/) they use) is that they (a) always check to make sure that the properties exist before additional validation (so you can skip one test step) and (b) generate more complete error messages on assertion failures (the default assertion errors do not mention named of the properties being checked, which makes them not that useful). Property validation functions are grouped under the `utils.expect.property` namespace and include:
453470

utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ utils = {
621621
// Expects response to contain an non-empty array.
622622
empty: function(pm) {
623623
utils.expect.response.many(pm, 1, -1);
624+
},
625+
// DESCRITION
626+
// Expects response to contain an array with at least two items.
627+
unique: function(pm) {
628+
utils.expect.response.many(pm, 2, -1);
624629
}
625630
}
626631
// End of 'utils.expect.response' functions.

0 commit comments

Comments
 (0)