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);
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.
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 .
It checks whether something is matched for a regular expression. You can use the toMatch matcher to test search patterns.
The toBeGreaterThan and toBeLessThan matchers check if something is greater than or less than something else.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With