expect.toBeWithin(number, number)
Use .toBeWithin
when you want to check that a number is within a range.
For example, if you want to test that ouncesPerCan()
returns a value between 5 and 20, write:
test('ounces per can is between 5 and 20', () => {
expect(ouncesPerCan()).toBeWithin(5, 20);
});
Install
npm i @coderbyheart/jest-expect-tobewithin
Usage
import { toBeWithin } from '@coderbyheart/jest-expect-tobewithin'
expect.extend({toBeWithin});
// In your test:
expect(10).toBeWithin(5,20)