Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-matcher-deep-close-to

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-matcher-deep-close-to - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

9

lib/index.js

@@ -14,2 +14,3 @@ 'use strict';

var error = recursiveCheck(received, expected, decimals);
/* istanbul ignore next */
if (error) {

@@ -43,3 +44,3 @@ return {

function recursiveCheck(actual, expected, decimals) {
if (typeof actual === 'number') {
if (typeof actual === 'number' && typeof expected === 'number') {
if ((Math.abs(actual - expected) <= Math.pow(10, -decimals))) {

@@ -54,3 +55,3 @@ return false;

}
} else if (Array.isArray(actual)) {
} else if (Array.isArray(actual) && Array.isArray(expected)) {
if (actual.length !== expected.length) {

@@ -72,4 +73,4 @@ return {

return {
reason: 'The current data type is not supported',
expected: 'number or Array',
reason: 'The current data type is not supported or they do not match',
expected: typeof expected,
received: typeof actual

@@ -76,0 +77,0 @@ };

{
"name": "jest-matcher-deep-close-to",
"version": "1.0.1",
"version": "1.0.2",
"description": "Extend jest to assert arrays with approximate values",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -16,5 +16,31 @@ import {toBeDeepCloseTo} from '..';

it('array of arrays', () => {
expect([42]).toBeDeepCloseTo([[42]], 3);
expect([[42]]).toBeDeepCloseTo([[42]], 3);
expect([[42.0003]]).toBeDeepCloseTo([[42.0004]], 3);
});
});
describe('fails', () => {
it('numbers', () => {
expect(43).not.toBeDeepCloseTo(42, 3);
expect(42.03).not.toBeDeepCloseTo(42.0004, 3);
});
it('array', () => {
expect([43]).not.toBeDeepCloseTo([42], 3);
expect([42.03]).not.toBeDeepCloseTo([42.0004], 3);
});
it('array of arrays', () => {
expect([[43]]).not.toBeDeepCloseTo([[42]], 3);
expect([[42.03]]).not.toBeDeepCloseTo([[42.0004]], 3);
});
it('array length', () => {
expect([[43]]).not.toBeDeepCloseTo([[43, 43]], 3);
});
it('data type', () => {
expect([[43]]).not.toBeDeepCloseTo([['43']], 3);
});
});

@@ -10,2 +10,3 @@ /**

var error = recursiveCheck(received, expected, decimals);
/* istanbul ignore next */
if (error) {

@@ -39,3 +40,3 @@ return {

function recursiveCheck(actual, expected, decimals) {
if (typeof actual === 'number') {
if (typeof actual === 'number' && typeof expected === 'number') {
if ((Math.abs(actual - expected) <= Math.pow(10, -decimals))) {

@@ -50,3 +51,3 @@ return false;

}
} else if (Array.isArray(actual)) {
} else if (Array.isArray(actual) && Array.isArray(expected)) {
if (actual.length !== expected.length) {

@@ -68,4 +69,4 @@ return {

return {
reason: 'The current data type is not supported',
expected: 'number or Array',
reason: 'The current data type is not supported or they do not match',
expected: typeof expected,
received: typeof actual

@@ -72,0 +73,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc