最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can we assert the boolean data type in postman tests - Stack Overflow

programmeradmin6浏览0评论

I want to assert the boolean data type in the postman. The data value could have true or false. How should we achieve this? I m using this code to verify but it will pass only if it's true but I want to validate if the value is false as well.

pm.test("Verify the past event dvr details", function () {
    var jsonData = pm.response.json();
 pm.expect(jsonData.data.entries[0].live_stream_rule.target_stream.dvr.is_available).to.be.true;
});

I want to assert the boolean data type in the postman. The data value could have true or false. How should we achieve this? I m using this code to verify but it will pass only if it's true but I want to validate if the value is false as well.

pm.test("Verify the past event dvr details", function () {
    var jsonData = pm.response.json();
 pm.expect(jsonData.data.entries[0].live_stream_rule.target_stream.dvr.is_available).to.be.true;
});
Share Improve this question edited Nov 21, 2020 at 11:14 Sarun UK 6,7667 gold badges26 silver badges50 bronze badges asked Nov 21, 2020 at 10:34 Prabu GauthamPrabu Gautham 611 silver badge2 bronze badges 1
  • You would need to add chaijs./plugins/chai-asserttype to be able to check if it's a boolean. What other values could it be? Are you trying to make sure that it exists? – Arlemi Commented Nov 23, 2020 at 15:01
Add a ment  | 

2 Answers 2

Reset to default 3
pm.test("Verify the past event dvr details", function () {
    var jsonData = pm.response.json();
 pm.expect(jsonData.data.entries[0].live_stream_rule.target_stream.dvr.is_available).to.be.a("boolean");
});

[PLEASE NOTE: This answer is incorrect and contains invalid code- see answer by Stanislav Scurtu]

If this what you're thinking of?

const isAvailable = jsonData.data.entries[0].live_stream_rule.target_stream.dvr.is_available
pm.expect(typeof isAvailable).to.be('boolean')
发布评论

评论列表(0)

  1. 暂无评论