Checking two borders with Jasmine (between matches)

toBeGreaterThan has toBeGreaterThan and toBeLessThan .

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

I can currently solve it with two different expect calls:

 var x = 3; expect(x).toBeGreaterThan(1); expect(x).toBeLessThan(10); 
+9
javascript assertions testing jasmine
Feb 26 '15 at 1:21
source share
1 answer

You can run a logical comparison and validate the result to true :

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

In addition, there is toBeWithinRange() custom match introduced by jasmine-matchers :

 expect(x).toBeWithinRange(2, 9); // range borders are included 
+12
Feb 26 '15 at 1:21
source share



All Articles