本文介绍了用 Jasmine 检查两个边界(在匹配器之间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Jasmine 中,有 toBeGreaterThan
和 toBeLessThan
匹配器.
In Jasmine, there are toBeGreaterThan
and toBeLessThan
matchers.
如果我想检查特定范围内的整数值怎么办?有没有类似 toBeInBetween
匹配器的东西?
What if I want to check an integer value in a specific range? Is there anything like toBeInBetween
matcher?
目前,我可以通过两个单独的 expect
调用来解决它:
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();
此外,还有由 jasmine 引入的
:toBeWithinRange()
自定义匹配器-匹配器
Also, there is toBeWithinRange()
custom matcher introduced by jasmine-matchers
:
expect(x).toBeWithinRange(2, 9); // range borders are included
这篇关于用 Jasmine 检查两个边界(在匹配器之间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!