jest-matcher-deep-close-to
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -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 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9654
177