Extend jest to assert arrays and objects with approximate values.
$ npm i -D jest-matcher-deep-close-to
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);
});
});