Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

coderbyheart/jest-expect-toBeWithin

Repository files navigation

expect.toBeWithin(number, number)

npm tested with jest Build Status Greenkeeper badge semantic-release Commitizen friendly Standard - JavaScript Style Guide

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)