在 Jasmine 中,有toBeGreaterThan和toBeLessThan匹配器。
如果我想检查特定范围内的整数值怎么办?有没有类似toBeInBetweenmatcher的东西?
目前,我可以通过两个单独的expect调用来解决它:
var x = 3;
expect(x).toBeGreaterThan(1);
expect(x).toBeLessThan(10);
在 Jasmine 中,有toBeGreaterThan和toBeLessThan匹配器。
如果我想检查特定范围内的整数值怎么办?有没有类似toBeInBetweenmatcher的东西?
目前,我可以通过两个单独的expect调用来解决它:
var x = 3;
expect(x).toBeGreaterThan(1);
expect(x).toBeLessThan(10);
您可以运行布尔比较并断言结果为true:
expect(x > 1 && x < 10).toBeTruthy();
此外,还toBeWithinRange()引入了自定义匹配器jasmine-matchers:
expect(x).toBeWithinRange(2, 9); // range borders are included