Checking two boundaries with Jasmine (between matc

2020-02-25 23:18发布

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条回答
手持菜刀,她持情操
2楼-- · 2020-02-26 00:04

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 
查看更多
登录 后发表回答