使用Jasmine检查两个边界(在匹配器之间) [英] Checking two boundaries with Jasmine (between matcher)

查看:122
本文介绍了使用Jasmine检查两个边界(在匹配器之间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jasmine中,有 toBeGreaterThan toBeLessThan 匹配器。

In Jasmine, there are toBeGreaterThan and toBeLessThan matchers.

如果我想检查特定范围内的整数值怎么办?有什么像 toBeInBetween matcher?

What if I want to check an integer value in a specific range? Is there anything like toBeInBetween matcher?

目前,我可以在两个单独的中解决它期待来电:

Currently, I can solve it in two separate expect calls:

var x = 3;

expect(x).toBeGreaterThan(1);
expect(x).toBeLessThan(10);


推荐答案

你可以运行布尔比较并断言结果是 true

You can run the boolean comparison and assert the result is true:

expect(x > 1 && x < 10).toBeTruthy();

此外,还有 toBeWithinRange()自定义matcher由 jasmine-matchers 介绍:

Also, there is toBeWithinRange() custom matcher introduced by jasmine-matchers:

expect(x).toBeWithinRange(2, 9);  // range borders are included 

这篇关于使用Jasmine检查两个边界(在匹配器之间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆