How to test a range of numbers with Jest?
If they are decimal numbers you can use .toBeCloseTo
test('adding works sanely with decimals', () => {
expect(0.2 + 0.1).toBeCloseTo(0.3);
});
Using methods .toBeGreaterThanOrEqual
and .toBeLessThan
:
const value = ...
expect(value).toBeGreaterThanOrEqual(lower_inclusive);
expect(value).toBeLessThan(upper_exclusive);