Skip to content

maasencioh/jest-matcher-deep-close-to

Repository files navigation

jest-matcher-deep-close-to

NPM version build status npm download

Extend jest to assert arrays and objects with approximate values.

Installation

$ npm i -D jest-matcher-deep-close-to

Usage

import { toBeDeepCloseTo,toMatchCloseTo } from 'jest-matcher-deep-close-to';
expect.extend({toBeDeepCloseTo, toMatchCloseTo});

describe('test myModule', () => {
    it('should return 42', () => {
        expect([42.0003]).toBeDeepCloseTo([42.0004], 3);
    });
});

describe('test myModule', () => {
    it('should return 42', () => {
        expect({ foo: 42.0003,  bar: "xxx", baz: "yyy"})
            .toMatchCloseTo({ foo: 42.004, bar: "xxx" }, 3);
    });
});

License

MIT