expect
Advanced tools
Comparing version 27.4.6 to 27.5.0
@@ -56,2 +56,9 @@ /** | ||
} | ||
declare class CloseTo extends AsymmetricMatcher<number> { | ||
private precision; | ||
constructor(sample: number, precision?: number, inverse?: boolean); | ||
asymmetricMatch(other: number): boolean; | ||
toString(): string; | ||
getExpectedType(): string; | ||
} | ||
export declare const any: (expectedObject: unknown) => Any; | ||
@@ -67,2 +74,4 @@ export declare const anything: () => Anything; | ||
export declare const stringNotMatching: (expected: string | RegExp) => StringMatching; | ||
export declare const closeTo: (expected: number, precision?: number | undefined) => CloseTo; | ||
export declare const notCloseTo: (expected: number, precision?: number | undefined) => CloseTo; | ||
export {}; |
@@ -12,2 +12,4 @@ 'use strict'; | ||
exports.objectContaining = | ||
exports.notCloseTo = | ||
exports.closeTo = | ||
exports.arrayNotContaining = | ||
@@ -338,2 +340,48 @@ exports.arrayContaining = | ||
class CloseTo extends AsymmetricMatcher { | ||
constructor(sample, precision = 2, inverse = false) { | ||
if (!(0, _jasmineUtils.isA)('Number', sample)) { | ||
throw new Error('Expected is not a Number'); | ||
} | ||
if (!(0, _jasmineUtils.isA)('Number', precision)) { | ||
throw new Error('Precision is not a Number'); | ||
} | ||
super(sample); | ||
_defineProperty(this, 'precision', void 0); | ||
this.inverse = inverse; | ||
this.precision = precision; | ||
} | ||
asymmetricMatch(other) { | ||
if (!(0, _jasmineUtils.isA)('Number', other)) { | ||
return false; | ||
} | ||
let result = false; | ||
if (other === Infinity && this.sample === Infinity) { | ||
result = true; // Infinity - Infinity is NaN | ||
} else if (other === -Infinity && this.sample === -Infinity) { | ||
result = true; // -Infinity - -Infinity is NaN | ||
} else { | ||
result = | ||
Math.abs(this.sample - other) < Math.pow(10, -this.precision) / 2; | ||
} | ||
return this.inverse ? !result : result; | ||
} | ||
toString() { | ||
return `Number${this.inverse ? 'Not' : ''}CloseTo`; | ||
} | ||
getExpectedType() { | ||
return 'number'; | ||
} | ||
} | ||
const any = expectedObject => new Any(expectedObject); | ||
@@ -378,1 +426,10 @@ | ||
exports.stringNotMatching = stringNotMatching; | ||
const closeTo = (expected, precision) => new CloseTo(expected, precision); | ||
exports.closeTo = closeTo; | ||
const notCloseTo = (expected, precision) => | ||
new CloseTo(expected, precision, true); | ||
exports.notCloseTo = notCloseTo; |
@@ -416,2 +416,3 @@ 'use strict'; | ||
arrayContaining: _asymmetricMatchers.arrayNotContaining, | ||
closeTo: _asymmetricMatchers.notCloseTo, | ||
objectContaining: _asymmetricMatchers.objectNotContaining, | ||
@@ -421,4 +422,5 @@ stringContaining: _asymmetricMatchers.stringNotContaining, | ||
}; | ||
expect.arrayContaining = _asymmetricMatchers.arrayContaining; | ||
expect.closeTo = _asymmetricMatchers.closeTo; | ||
expect.objectContaining = _asymmetricMatchers.objectContaining; | ||
expect.arrayContaining = _asymmetricMatchers.arrayContaining; | ||
expect.stringContaining = _asymmetricMatchers.stringContaining; | ||
@@ -425,0 +427,0 @@ expect.stringMatching = _asymmetricMatchers.stringMatching; |
@@ -411,6 +411,11 @@ 'use strict'; | ||
const pathAsArray = propertyPath => { | ||
// will match everything that's not a dot or a bracket, and "" for consecutive dots. | ||
const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g'); | ||
const properties = []; // Because the regex won't match a dot in the beginning of the path, if present. | ||
const properties = []; | ||
if (propertyPath === '') { | ||
properties.push(''); | ||
return properties; | ||
} // will match everything that's not a dot or a bracket, and "" for consecutive dots. | ||
const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g'); // Because the regex won't match a dot in the beginning of the path, if present. | ||
if (propertyPath[0] === '.') { | ||
@@ -417,0 +422,0 @@ properties.push(''); |
{ | ||
"name": "expect", | ||
"version": "27.4.6", | ||
"version": "27.5.0", | ||
"repository": { | ||
@@ -22,12 +22,14 @@ "type": "git", | ||
"dependencies": { | ||
"@jest/types": "^27.4.2", | ||
"jest-get-type": "^27.4.0", | ||
"jest-matcher-utils": "^27.4.6", | ||
"jest-message-util": "^27.4.6" | ||
"@jest/types": "^27.5.0", | ||
"jest-get-type": "^27.5.0", | ||
"jest-matcher-utils": "^27.5.0", | ||
"jest-message-util": "^27.5.0" | ||
}, | ||
"devDependencies": { | ||
"@jest/test-utils": "^27.4.6", | ||
"@jest/test-utils": "^27.5.0", | ||
"@tsd/typescript": "~4.1.5", | ||
"chalk": "^4.0.0", | ||
"fast-check": "^2.0.0", | ||
"immutable": "^4.0.0" | ||
"immutable": "^4.0.0", | ||
"tsd-lite": "^0.5.1" | ||
}, | ||
@@ -40,3 +42,3 @@ "engines": { | ||
}, | ||
"gitHead": "644d2d3e53536b0d67e395c0f35f8555a67beb1e" | ||
"gitHead": "247cbe6026a590deaf0d23edecc7b2779a4aace9" | ||
} |
172028
5092
6
Updated@jest/types@^27.5.0
Updatedjest-get-type@^27.5.0
Updatedjest-matcher-utils@^27.5.0
Updatedjest-message-util@^27.5.0