jest-matcher-utils
Advanced tools
Comparing version 24.0.0 to 24.2.0-alpha.0
@@ -6,7 +6,13 @@ 'use strict'; | ||
}); | ||
exports.matcherHint = exports.matcherErrorMessage = exports.getLabelPrinter = exports.pluralize = exports.diff = exports.ensureNumbers = exports.ensureExpectedIsNumber = exports.ensureActualIsNumber = exports.ensureNoExpected = exports.printWithType = exports.printExpected = exports.printReceived = exports.highlightTrailingWhitespace = exports.stringify = exports.SUGGEST_TO_CONTAIN_EQUAL = exports.SUGGEST_TO_EQUAL = exports.RECEIVED_COLOR = exports.EXPECTED_COLOR = void 0; | ||
Object.defineProperty(exports, 'DiffOptions', { | ||
enumerable: true, | ||
get: function get() { | ||
return _jestDiff.DiffOptions; | ||
} | ||
}); | ||
exports.matcherHint = exports.matcherErrorMessage = exports.getLabelPrinter = exports.pluralize = exports.diff = exports.ensureExpectedIsNonNegativeInteger = exports.ensureNumbers = exports.ensureExpectedIsNumber = exports.ensureActualIsNumber = exports.ensureNoExpected = exports.printWithType = exports.printExpected = exports.printReceived = exports.highlightTrailingWhitespace = exports.stringify = exports.SUGGEST_TO_CONTAIN_EQUAL = exports.SUGGEST_TO_EQUAL = exports.INVERTED_COLOR = exports.RECEIVED_COLOR = exports.EXPECTED_COLOR = void 0; | ||
var _chalk = _interopRequireDefault(require('chalk')); | ||
var _jestDiff = _interopRequireDefault(require('jest-diff')); | ||
var _jestDiff = _interopRequireWildcard(require('jest-diff')); | ||
@@ -17,2 +23,27 @@ var _jestGetType = _interopRequireDefault(require('jest-get-type')); | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} else { | ||
var newObj = {}; | ||
if (obj != null) { | ||
for (var key in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = | ||
Object.defineProperty && Object.getOwnPropertyDescriptor | ||
? Object.getOwnPropertyDescriptor(obj, key) | ||
: {}; | ||
if (desc.get || desc.set) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
return newObj; | ||
} | ||
} | ||
function _interopRequireDefault(obj) { | ||
@@ -27,4 +58,2 @@ return obj && obj.__esModule ? obj : {default: obj}; | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
@@ -50,2 +79,4 @@ const _prettyFormat$plugins = _prettyFormat.default.plugins, | ||
exports.RECEIVED_COLOR = RECEIVED_COLOR; | ||
const INVERTED_COLOR = _chalk.default.inverse; | ||
exports.INVERTED_COLOR = INVERTED_COLOR; | ||
const DIM_COLOR = _chalk.default.dim; | ||
@@ -145,3 +176,2 @@ const NUMBERS = [ | ||
matcherHint(matcherString, undefined, '', options), // Because expected is omitted in hint above, | ||
// expected is black instead of green in message below. | ||
'this matcher must not have an expected argument', | ||
@@ -156,9 +186,9 @@ printWithType('Expected', expected, printExpected) | ||
const ensureActualIsNumber = (actual, matcherName) => { | ||
matcherName || (matcherName = 'This matcher'); | ||
const ensureActualIsNumber = (actual, matcherName, options) => { | ||
if (typeof actual !== 'number') { | ||
// Prepend maybe not only for backward compatibility. | ||
const matcherString = (options ? '' : '[.not]') + matcherName; | ||
throw new Error( | ||
matcherErrorMessage( | ||
matcherHint('[.not]' + matcherName), | ||
matcherHint(matcherString, undefined, undefined, options), | ||
`${RECEIVED_COLOR('received')} value must be a number`, | ||
@@ -173,9 +203,9 @@ printWithType('Received', actual, printReceived) | ||
const ensureExpectedIsNumber = (expected, matcherName) => { | ||
matcherName || (matcherName = 'This matcher'); | ||
const ensureExpectedIsNumber = (expected, matcherName, options) => { | ||
if (typeof expected !== 'number') { | ||
// Prepend maybe not only for backward compatibility. | ||
const matcherString = (options ? '' : '[.not]') + matcherName; | ||
throw new Error( | ||
matcherErrorMessage( | ||
matcherHint('[.not]' + matcherName), | ||
matcherHint(matcherString, undefined, undefined, options), | ||
`${EXPECTED_COLOR('expected')} value must be a number`, | ||
@@ -190,5 +220,25 @@ printWithType('Expected', expected, printExpected) | ||
const ensureNumbers = (actual, expected, matcherName) => { | ||
ensureActualIsNumber(actual, matcherName); | ||
ensureExpectedIsNumber(expected, matcherName); | ||
const ensureNumbers = (actual, expected, matcherName, options) => { | ||
ensureActualIsNumber(actual, matcherName, options); | ||
ensureExpectedIsNumber(expected, matcherName, options); | ||
}; | ||
exports.ensureNumbers = ensureNumbers; | ||
const ensureExpectedIsNonNegativeInteger = (expected, matcherName, options) => { | ||
if ( | ||
typeof expected !== 'number' || | ||
!Number.isSafeInteger(expected) || | ||
expected < 0 | ||
) { | ||
// Prepend maybe not only for backward compatibility. | ||
const matcherString = (options ? '' : '[.not]') + matcherName; | ||
throw new Error( | ||
matcherErrorMessage( | ||
matcherHint(matcherString, undefined, undefined, options), | ||
`${EXPECTED_COLOR('expected')} value must be a non-negative integer`, | ||
printWithType('Expected', expected, printExpected) | ||
) | ||
); | ||
} | ||
}; // Sometimes, e.g. when comparing two numbers, the output from jest-diff | ||
@@ -198,3 +248,3 @@ // does not contain more information than the `Expected:` / `Received:` already gives. | ||
exports.ensureNumbers = ensureNumbers; | ||
exports.ensureExpectedIsNonNegativeInteger = ensureExpectedIsNonNegativeInteger; | ||
@@ -201,0 +251,0 @@ const shouldPrintDiff = (actual, expected) => { |
{ | ||
"name": "jest-matcher-utils", | ||
"description": "A set of utility functions for expect and related packages", | ||
"version": "24.0.0", | ||
"version": "24.2.0-alpha.0", | ||
"repository": { | ||
@@ -17,7 +17,10 @@ "type": "git", | ||
"chalk": "^2.0.1", | ||
"jest-diff": "^24.0.0", | ||
"jest-get-type": "^24.0.0", | ||
"pretty-format": "^24.0.0" | ||
"jest-diff": "^24.2.0-alpha.0", | ||
"jest-get-type": "^24.2.0-alpha.0", | ||
"pretty-format": "^24.2.0-alpha.0" | ||
}, | ||
"gitHead": "634e5a54f46b2a62d1dc81a170562e6f4e55ad60" | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "800f2f803d01c8ae194d71b251e4965dd70e5bf2" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15483
5
357
2
Updatedjest-diff@^24.2.0-alpha.0