F
F
Frisby
Search…
Nested Tests
Sometimes you have some HTTP calls that are dependent on others, like creating a new item and then checking to ensure that it exists and is returned from the API.
Here is a more complex test example with nested dependent Frisby tests with Frisby's Promise-style `then` method.
1
const frisby = require('frisby');
2
const Joi = frisby.Joi; // Frisby exposes Joi for convenience
3
4
describe('Posts', function () {
5
it('should return all posts and first post should have comments', function () {
6
return frisby.get('http://jsonplaceholder.typicode.com/posts')
7
.expect('status', 200)
8
.expect('jsonTypes', '*', {
9
userId: Joi.number(),
10
id: Joi.number(),
11
title: Joi.string(),
12
body: Joi.string()
13
})
14
.then(function (res) { // res = FrisbyResponse object
15
let postId = res.json[0].id;
16
17
// Get first post's comments
18
// RETURN the FrisbySpec object so function waits on it to finish - just like a Promise chain
19
return frisby.get('http://jsonplaceholder.typicode.com/posts/' + postId + '/comments')
20
.expect('status', 200)
21
.expect('json', '*', {
22
postId: postId
23
})
24
.expect('jsonTypes', '*', {
25
postId: Joi.number(),
26
id: Joi.number(),
27
name: Joi.string(),
28
email: Joi.string().email(),
29
body: Joi.string()
30
});
31
});
32
});
33
});
Copied!
```
Last modified 1yr ago
Copy link