Checking two boundaries with Jasmine (between matcher)

百般思念 提交于 2019-11-29 08:17:41

问题


In Jasmine, there are toBeGreaterThan and toBeLessThan matchers.

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);

回答1:


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

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

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

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


来源:https://stackoverflow.com/questions/28732881/checking-two-boundaries-with-jasmine-between-matcher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!