Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking two boundaries with Jasmine (between matcher)

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);
like image 499
alecxe Avatar asked Feb 26 '15 01:02

alecxe


People also ask

Which matcher is used in jasmine to check whether the result is equal to true or false?

ToBeTruthy() This Boolean matcher is used in Jasmine to check whether the result is equal to true or false. The following example will help us understand the working principle of the toBeTruthy() function.

How do you compare objects in Jasmine?

You can customize how jasmine determines if two objects are equal by defining your own custom equality testers. A custom equality tester is a function that takes two arguments. If the custom equality tester knows how to compare the two items, it should return either true or false .

Which of the following Jasmine matchers can be used to check for a regular expression?

It checks whether something is matched for a regular expression. You can use the toMatch matcher to test search patterns.

Which matcher function is tested greater than condition?

The toBeGreaterThan and toBeLessThan matchers check if something is greater than or less than something else.


1 Answers

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 
like image 63
alecxe Avatar answered Nov 10 '22 03:11

alecxe