tobewithin jest

Solutions on MaxInterview for tobewithin jest by the best coders in the world

showing results for - "tobewithin jest"
Vanessa
22 May 2016
1expect.extend({
2  toBeWithinRange(received, floor, ceiling) {
3    const pass = received >= floor && received <= ceiling;
4    if (pass) {
5      return {
6        message: () =>
7          `expected ${received} not to be within range ${floor} - ${ceiling}`,
8        pass: true,
9      };
10    } else {
11      return {
12        message: () =>
13          `expected ${received} to be within range ${floor} - ${ceiling}`,
14        pass: false,
15      };
16    }
17  },
18});
19
20test('numeric ranges', () => {
21  expect(100).toBeWithinRange(90, 110);
22  expect(101).not.toBeWithinRange(0, 100);
23  expect({apples: 6, bananas: 3}).toEqual({
24    apples: expect.toBeWithinRange(1, 10),
25    bananas: expect.not.toBeWithinRange(11, 20),
26  });
27});
28Copy
queries leading to this page
tobewithin jesttobewithin jest