-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: template name and file name in expect json
- Loading branch information
1 parent
c5adbe8
commit 6e8f388
Showing
8 changed files
with
231 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"pactum" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,20 @@ Performs deep equal of JSON objects. | |
|
||
```js | ||
expectJson(json) | ||
expectJson(path, json) | ||
expectJson(template-name) | ||
expectJson(file-path) | ||
expectJson(file-name) | ||
expectJson(json-path, json) | ||
``` | ||
|
||
## Usage | ||
|
||
### ✅ Correct Usage | ||
|
||
```js | ||
```js | ||
await spec() | ||
.get('api/health') | ||
.expectJson({ | ||
.expectJson({ | ||
message: 'OK' | ||
}); | ||
``` | ||
|
@@ -33,7 +36,15 @@ await spec() | |
|
||
Response json body. | ||
|
||
#### > path (string) | ||
#### > template-name (string) | ||
|
||
name of the data template to use. | ||
|
||
#### > file-name (string) | ||
|
||
name of the json file to use. | ||
|
||
#### > json-path (string) | ||
|
||
Json path. See [json-query](https://www.npmjs.com/package/json-query) for more usage details. | ||
|
||
|
@@ -70,4 +81,55 @@ await spec() | |
.get('https://reqres.in/api/users/1') | ||
.expectJson('data.first_name', 'George') | ||
.expectJson('data.last_name', 'Bluth'); | ||
``` | ||
``` | ||
|
||
### Using data template | ||
|
||
```js | ||
const { spec, stash } = require('pactum'); | ||
|
||
stash.addDataTemplate({ | ||
'FIRST_USER': { | ||
"data": { | ||
"id": 1, | ||
"email": "[email protected]", | ||
"first_name": "George", | ||
"last_name": "Bluth", | ||
"avatar": "https://reqres.in/img/faces/1-image.jpg" | ||
}, | ||
"support": { | ||
"url": "https://reqres.in/#support-heading", | ||
"text": "To keep ReqRes free, contributions towards server costs are appreciated!" | ||
} | ||
} | ||
}); | ||
|
||
await spec() | ||
.get('https://reqres.in/api/users/1') | ||
.expectJson('FIRST_USER'); | ||
``` | ||
|
||
### Using file path | ||
|
||
```js | ||
const { spec } = require('pactum'); | ||
|
||
await spec() | ||
.get('https://reqres.in/api/users/1') | ||
.expectJson('./data/user.json'); | ||
``` | ||
|
||
#### Using file name | ||
|
||
```js | ||
const { spec } = require('pactum'); | ||
|
||
await spec() | ||
.get('https://reqres.in/api/users/1') | ||
.expectJson('user.json') // searches for the file inside the data folder | ||
.expectStatus(201); | ||
``` | ||
|
||
## See Also | ||
|
||
- [setDataDirectory](/api/settings/setDataDirectory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,20 @@ Performs partial equal of JSON objects. | |
|
||
```js | ||
expectJsonLike(json) | ||
expectJson(template-name) | ||
expectJson(file-path) | ||
expectJson(file-name) | ||
expectJsonLike(path, json) | ||
``` | ||
|
||
## Usage | ||
|
||
### ✅ Correct Usage | ||
|
||
```js | ||
```js | ||
await spec() | ||
.get('api/health') | ||
.expectJsonLike({ | ||
.expectJsonLike({ | ||
message: 'OK' | ||
}); | ||
``` | ||
|
@@ -61,6 +64,49 @@ await spec() | |
}); | ||
``` | ||
|
||
### Using data template | ||
|
||
```js | ||
const { spec, stash } = require('pactum'); | ||
|
||
stash.addDataTemplate({ | ||
'FIRST_USER': { | ||
"data": { | ||
"id": 1, | ||
"email": "[email protected]", | ||
"first_name": "George", | ||
"last_name": "Bluth", | ||
"avatar": "https://reqres.in/img/faces/1-image.jpg" | ||
} | ||
} | ||
}); | ||
|
||
await spec() | ||
.get('https://reqres.in/api/users/1') | ||
.expectJsonLike('FIRST_USER'); | ||
``` | ||
|
||
### Using file path | ||
|
||
```js | ||
const { spec } = require('pactum'); | ||
|
||
await spec() | ||
.get('https://reqres.in/api/users/1') | ||
.expectJsonLike('./data/user.json'); | ||
``` | ||
|
||
#### Using file name | ||
|
||
```js | ||
const { spec } = require('pactum'); | ||
|
||
await spec() | ||
.post('https://reqres.in/api/users') | ||
.expectJsonLike('user.json') // searches for the file inside the data folder | ||
.expectStatus(201); | ||
``` | ||
|
||
### Regular Expressions | ||
|
||
```js | ||
|
@@ -79,7 +125,7 @@ await spec() | |
|
||
### Assert Expressions | ||
|
||
Assert Expressions helps to run custom JavaScript code on a JSON that performs user defined assertions. | ||
Assert Expressions helps to run custom JavaScript code on a JSON that performs user defined assertions. | ||
|
||
- Expression should contain `$V` to represent current value. | ||
- Expression should be a valid JavaScript code. | ||
|
@@ -121,4 +167,5 @@ await spec() | |
|
||
## See Also | ||
|
||
- [Assert Handlers](/api/handlers/addAssertHandler) | ||
- [Assert Handlers](/api/handlers/addAssertHandler) | ||
- [setDataDirectory](/api/settings/setDataDirectory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.