jest-matcher-utils
Advanced tools
Comparing version 29.7.0 to 30.0.0-alpha.1
@@ -1,41 +0,215 @@ | ||
'use strict'; | ||
/*! | ||
* /** | ||
* * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* * | ||
* * This source code is licensed under the MIT license found in the | ||
* * LICENSE file in the root directory of this source tree. | ||
* * / | ||
*/ | ||
/******/ (() => { // webpackBootstrap | ||
/******/ "use strict"; | ||
/******/ var __webpack_modules__ = ({ | ||
Object.defineProperty(exports, '__esModule', { | ||
/***/ "./src/Replaceable.ts": | ||
/***/ ((__unused_webpack_module, exports) => { | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
}); | ||
exports.printReceived = | ||
exports.printExpected = | ||
exports.printDiffOrStringify = | ||
exports.pluralize = | ||
exports.matcherHint = | ||
exports.matcherErrorMessage = | ||
exports.highlightTrailingWhitespace = | ||
exports.getLabelPrinter = | ||
exports.ensureNumbers = | ||
exports.ensureNoExpected = | ||
exports.ensureExpectedIsNumber = | ||
exports.ensureExpectedIsNonNegativeInteger = | ||
exports.ensureActualIsNumber = | ||
exports.diff = | ||
exports.SUGGEST_TO_CONTAIN_EQUAL = | ||
exports.RECEIVED_COLOR = | ||
exports.INVERTED_COLOR = | ||
exports.EXPECTED_COLOR = | ||
exports.DIM_COLOR = | ||
exports.BOLD_WEIGHT = | ||
void 0; | ||
})); | ||
exports["default"] = void 0; | ||
var _jestGetType = require("jest-get-type"); | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const supportTypes = ['map', 'array', 'object']; | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
class Replaceable { | ||
object; | ||
type; | ||
constructor(object) { | ||
this.object = object; | ||
this.type = (0, _jestGetType.getType)(object); | ||
if (!supportTypes.includes(this.type)) { | ||
throw new Error(`Type ${this.type} is not support in Replaceable!`); | ||
} | ||
} | ||
static isReplaceable(obj1, obj2) { | ||
const obj1Type = (0, _jestGetType.getType)(obj1); | ||
const obj2Type = (0, _jestGetType.getType)(obj2); | ||
return obj1Type === obj2Type && supportTypes.includes(obj1Type); | ||
} | ||
forEach(cb) { | ||
if (this.type === 'object') { | ||
const descriptors = Object.getOwnPropertyDescriptors(this.object); | ||
for (const key of [...Object.keys(descriptors), ...Object.getOwnPropertySymbols(descriptors)] | ||
//@ts-expect-error because typescript do not support symbol key in object | ||
//https://github.com/microsoft/TypeScript/issues/1863 | ||
.filter(key => descriptors[key].enumerable)) { | ||
cb(this.object[key], key, this.object); | ||
} | ||
} else { | ||
// eslint-disable-next-line unicorn/no-array-for-each | ||
this.object.forEach(cb); | ||
} | ||
} | ||
get(key) { | ||
if (this.type === 'map') { | ||
return this.object.get(key); | ||
} | ||
return this.object[key]; | ||
} | ||
set(key, value) { | ||
if (this.type === 'map') { | ||
this.object.set(key, value); | ||
} else { | ||
this.object[key] = value; | ||
} | ||
} | ||
} | ||
/* eslint-enable */ | ||
exports["default"] = Replaceable; | ||
/***/ }), | ||
/***/ "./src/deepCyclicCopyReplaceable.ts": | ||
/***/ ((__unused_webpack_module, exports) => { | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
})); | ||
exports["default"] = deepCyclicCopyReplaceable; | ||
var _prettyFormat = require("pretty-format"); | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const builtInObject = [Array, Date, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, Map, Set, RegExp, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray]; | ||
if (typeof Buffer !== 'undefined') { | ||
builtInObject.push(Buffer); | ||
} | ||
const isBuiltInObject = object => builtInObject.includes(object.constructor); | ||
const isMap = value => value.constructor === Map; | ||
function deepCyclicCopyReplaceable(value, cycles = new WeakMap()) { | ||
if (typeof value !== 'object' || value === null) { | ||
return value; | ||
} else if (cycles.has(value)) { | ||
return cycles.get(value); | ||
} else if (Array.isArray(value)) { | ||
return deepCyclicCopyArray(value, cycles); | ||
} else if (isMap(value)) { | ||
return deepCyclicCopyMap(value, cycles); | ||
} else if (isBuiltInObject(value)) { | ||
return value; | ||
} else if (_prettyFormat.plugins.DOMElement.test(value)) { | ||
return value.cloneNode(true); | ||
} else { | ||
return deepCyclicCopyObject(value, cycles); | ||
} | ||
} | ||
function deepCyclicCopyObject(object, cycles) { | ||
const newObject = Object.create(Object.getPrototypeOf(object)); | ||
let descriptors = {}; | ||
let obj = object; | ||
do { | ||
descriptors = Object.assign({}, Object.getOwnPropertyDescriptors(obj), descriptors); | ||
} while ((obj = Object.getPrototypeOf(obj)) && obj !== Object.getPrototypeOf({})); | ||
cycles.set(object, newObject); | ||
const newDescriptors = [...Object.keys(descriptors), ...Object.getOwnPropertySymbols(descriptors)].reduce( | ||
//@ts-expect-error because typescript do not support symbol key in object | ||
//https://github.com/microsoft/TypeScript/issues/1863 | ||
(newDescriptors, key) => { | ||
const enumerable = descriptors[key].enumerable; | ||
newDescriptors[key] = { | ||
configurable: true, | ||
enumerable, | ||
value: deepCyclicCopyReplaceable( | ||
// this accesses the value or getter, depending. We just care about the value anyways, and this allows us to not mess with accessors | ||
// it has the side effect of invoking the getter here though, rather than copying it over | ||
object[key], cycles), | ||
writable: true | ||
}; | ||
return newDescriptors; | ||
}, {}); | ||
//@ts-expect-error because typescript do not support symbol key in object | ||
//https://github.com/microsoft/TypeScript/issues/1863 | ||
return Object.defineProperties(newObject, newDescriptors); | ||
} | ||
function deepCyclicCopyArray(array, cycles) { | ||
const newArray = new (Object.getPrototypeOf(array).constructor)(array.length); | ||
const length = array.length; | ||
cycles.set(array, newArray); | ||
for (let i = 0; i < length; i++) { | ||
newArray[i] = deepCyclicCopyReplaceable(array[i], cycles); | ||
} | ||
return newArray; | ||
} | ||
function deepCyclicCopyMap(map, cycles) { | ||
const newMap = new Map(); | ||
cycles.set(map, newMap); | ||
for (const [key, value] of map.entries()) { | ||
newMap.set(key, deepCyclicCopyReplaceable(value, cycles)); | ||
} | ||
return newMap; | ||
} | ||
/***/ }) | ||
/******/ }); | ||
/************************************************************************/ | ||
/******/ // The module cache | ||
/******/ var __webpack_module_cache__ = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ // Check if module is in cache | ||
/******/ var cachedModule = __webpack_module_cache__[moduleId]; | ||
/******/ if (cachedModule !== undefined) { | ||
/******/ return cachedModule.exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = __webpack_module_cache__[moduleId] = { | ||
/******/ // no module.id needed | ||
/******/ // no module.loaded needed | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | ||
(() => { | ||
var exports = __webpack_exports__; | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
})); | ||
exports.printReceived = exports.printExpected = exports.printDiffOrStringify = exports.pluralize = exports.matcherHint = exports.matcherErrorMessage = exports.highlightTrailingWhitespace = exports.getLabelPrinter = exports.ensureNumbers = exports.ensureNoExpected = exports.ensureExpectedIsNumber = exports.ensureExpectedIsNonNegativeInteger = exports.ensureActualIsNumber = exports.diff = exports.SUGGEST_TO_CONTAIN_EQUAL = exports.RECEIVED_COLOR = exports.INVERTED_COLOR = exports.EXPECTED_COLOR = exports.DIM_COLOR = exports.BOLD_WEIGHT = void 0; | ||
exports.printWithType = printWithType; | ||
exports.replaceMatchedToAsymmetricMatcher = replaceMatchedToAsymmetricMatcher; | ||
exports.stringify = void 0; | ||
var _chalk = _interopRequireDefault(require('chalk')); | ||
var _jestDiff = require('jest-diff'); | ||
var _jestGetType = require('jest-get-type'); | ||
var _prettyFormat = require('pretty-format'); | ||
var _Replaceable = _interopRequireDefault(require('./Replaceable')); | ||
var _deepCyclicCopyReplaceable = _interopRequireDefault( | ||
require('./deepCyclicCopyReplaceable') | ||
); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
var _chalk = _interopRequireDefault(require("chalk")); | ||
var _jestDiff = require("jest-diff"); | ||
var _jestGetType = require("jest-get-type"); | ||
var _prettyFormat = require("pretty-format"); | ||
var _Replaceable = _interopRequireDefault(__webpack_require__("./src/Replaceable.ts")); | ||
var _deepCyclicCopyReplaceable = _interopRequireDefault(__webpack_require__("./src/deepCyclicCopyReplaceable.ts")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -58,48 +232,18 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
} = _prettyFormat.plugins; | ||
const PLUGINS = [ | ||
ReactTestComponent, | ||
ReactElement, | ||
DOMElement, | ||
DOMCollection, | ||
Immutable, | ||
AsymmetricMatcher | ||
]; | ||
const PLUGINS = [ReactTestComponent, ReactElement, DOMElement, DOMCollection, Immutable, AsymmetricMatcher]; | ||
// subset of Chalk type | ||
const EXPECTED_COLOR = _chalk.default.green; | ||
exports.EXPECTED_COLOR = EXPECTED_COLOR; | ||
const RECEIVED_COLOR = _chalk.default.red; | ||
exports.RECEIVED_COLOR = RECEIVED_COLOR; | ||
const INVERTED_COLOR = _chalk.default.inverse; | ||
exports.INVERTED_COLOR = INVERTED_COLOR; | ||
const BOLD_WEIGHT = _chalk.default.bold; | ||
exports.BOLD_WEIGHT = BOLD_WEIGHT; | ||
const DIM_COLOR = _chalk.default.dim; | ||
exports.DIM_COLOR = DIM_COLOR; | ||
const EXPECTED_COLOR = exports.EXPECTED_COLOR = _chalk.default.green; | ||
const RECEIVED_COLOR = exports.RECEIVED_COLOR = _chalk.default.red; | ||
const INVERTED_COLOR = exports.INVERTED_COLOR = _chalk.default.inverse; | ||
const BOLD_WEIGHT = exports.BOLD_WEIGHT = _chalk.default.bold; | ||
const DIM_COLOR = exports.DIM_COLOR = _chalk.default.dim; | ||
const MULTILINE_REGEXP = /\n/; | ||
const SPACE_SYMBOL = '\u{00B7}'; // middle dot | ||
const NUMBERS = [ | ||
'zero', | ||
'one', | ||
'two', | ||
'three', | ||
'four', | ||
'five', | ||
'six', | ||
'seven', | ||
'eight', | ||
'nine', | ||
'ten', | ||
'eleven', | ||
'twelve', | ||
'thirteen' | ||
]; | ||
const SUGGEST_TO_CONTAIN_EQUAL = _chalk.default.dim( | ||
'Looks like you wanted to test for object/array equality with the stricter `toContain` matcher. You probably need to use `toContainEqual` instead.' | ||
); | ||
exports.SUGGEST_TO_CONTAIN_EQUAL = SUGGEST_TO_CONTAIN_EQUAL; | ||
const NUMBERS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen']; | ||
const SUGGEST_TO_CONTAIN_EQUAL = exports.SUGGEST_TO_CONTAIN_EQUAL = _chalk.default.dim('Looks like you wanted to test for object/array equality with the stricter `toContain` matcher. You probably need to use `toContainEqual` instead.'); | ||
const stringify = (object, maxDepth = 10, maxWidth = 10) => { | ||
const MAX_LENGTH = 10000; | ||
const MAX_LENGTH = 10_000; | ||
let result; | ||
@@ -131,4 +275,3 @@ try { | ||
exports.stringify = stringify; | ||
const highlightTrailingWhitespace = text => | ||
text.replace(/\s+$/gm, _chalk.default.inverse('$&')); | ||
const highlightTrailingWhitespace = text => text.replace(/\s+$/gm, _chalk.default.inverse('$&')); | ||
@@ -138,16 +281,10 @@ // Instead of inverse highlight which now implies a change, | ||
exports.highlightTrailingWhitespace = highlightTrailingWhitespace; | ||
const replaceTrailingSpaces = text => | ||
text.replace(/\s+$/gm, spaces => SPACE_SYMBOL.repeat(spaces.length)); | ||
const printReceived = object => | ||
RECEIVED_COLOR(replaceTrailingSpaces(stringify(object))); | ||
const replaceTrailingSpaces = text => text.replace(/\s+$/gm, spaces => SPACE_SYMBOL.repeat(spaces.length)); | ||
const printReceived = object => RECEIVED_COLOR(replaceTrailingSpaces(stringify(object))); | ||
exports.printReceived = printReceived; | ||
const printExpected = value => | ||
EXPECTED_COLOR(replaceTrailingSpaces(stringify(value))); | ||
const printExpected = value => EXPECTED_COLOR(replaceTrailingSpaces(stringify(value))); | ||
exports.printExpected = printExpected; | ||
function printWithType(name, value, print) { | ||
const type = (0, _jestGetType.getType)(value); | ||
const hasType = | ||
type !== 'null' && type !== 'undefined' | ||
? `${name} has type: ${type}\n` | ||
: ''; | ||
const hasType = type !== 'null' && type !== 'undefined' ? `${name} has type: ${type}\n` : ''; | ||
const hasValue = `${name} has value: ${print(value)}`; | ||
@@ -160,11 +297,6 @@ return hasType + hasValue; | ||
const matcherString = (options ? '' : '[.not]') + matcherName; | ||
throw new Error( | ||
matcherErrorMessage( | ||
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', | ||
printWithType('Expected', expected, printExpected) | ||
) | ||
); | ||
throw new Error(matcherErrorMessage(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', printWithType('Expected', expected, printExpected))); | ||
} | ||
@@ -181,9 +313,3 @@ }; | ||
const matcherString = (options ? '' : '[.not]') + matcherName; | ||
throw new Error( | ||
matcherErrorMessage( | ||
matcherHint(matcherString, undefined, undefined, options), | ||
`${RECEIVED_COLOR('received')} value must be a number or bigint`, | ||
printWithType('Received', actual, printReceived) | ||
) | ||
); | ||
throw new Error(matcherErrorMessage(matcherHint(matcherString, undefined, undefined, options), `${RECEIVED_COLOR('received')} value must be a number or bigint`, printWithType('Received', actual, printReceived))); | ||
} | ||
@@ -200,9 +326,3 @@ }; | ||
const matcherString = (options ? '' : '[.not]') + matcherName; | ||
throw new Error( | ||
matcherErrorMessage( | ||
matcherHint(matcherString, undefined, undefined, options), | ||
`${EXPECTED_COLOR('expected')} value must be a number or bigint`, | ||
printWithType('Expected', expected, printExpected) | ||
) | ||
); | ||
throw new Error(matcherErrorMessage(matcherHint(matcherString, undefined, undefined, options), `${EXPECTED_COLOR('expected')} value must be a number or bigint`, printWithType('Expected', expected, printExpected))); | ||
} | ||
@@ -221,16 +341,6 @@ }; | ||
const ensureExpectedIsNonNegativeInteger = (expected, matcherName, options) => { | ||
if ( | ||
typeof expected !== 'number' || | ||
!Number.isSafeInteger(expected) || | ||
expected < 0 | ||
) { | ||
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) | ||
) | ||
); | ||
throw new Error(matcherErrorMessage(matcherHint(matcherString, undefined, undefined, options), `${EXPECTED_COLOR('expected')} value must be a non-negative integer`, printWithType('Expected', expected, printExpected))); | ||
} | ||
@@ -245,15 +355,3 @@ }; | ||
exports.ensureExpectedIsNonNegativeInteger = ensureExpectedIsNonNegativeInteger; | ||
const getCommonAndChangedSubstrings = (diffs, op, hasCommonDiff) => | ||
diffs.reduce( | ||
(reduced, diff) => | ||
reduced + | ||
(diff[0] === _jestDiff.DIFF_EQUAL | ||
? diff[1] | ||
: diff[0] !== op | ||
? '' | ||
: hasCommonDiff | ||
? INVERTED_COLOR(diff[1]) | ||
: diff[1]), | ||
'' | ||
); | ||
const getCommonAndChangedSubstrings = (diffs, op, hasCommonDiff) => diffs.reduce((reduced, diff) => reduced + (diff[0] === _jestDiff.DIFF_EQUAL ? diff[1] : diff[0] === op ? hasCommonDiff ? INVERTED_COLOR(diff[1]) : diff[1] : ''), ''); | ||
const isLineDiffable = (expected, received) => { | ||
@@ -269,15 +367,5 @@ const expectedType = (0, _jestGetType.getType)(expected); | ||
// * if either string has more than one line | ||
return ( | ||
typeof expected === 'string' && | ||
typeof received === 'string' && | ||
expected.length !== 0 && | ||
received.length !== 0 && | ||
(MULTILINE_REGEXP.test(expected) || MULTILINE_REGEXP.test(received)) | ||
); | ||
return typeof expected === 'string' && typeof received === 'string' && expected.length > 0 && received.length > 0 && (MULTILINE_REGEXP.test(expected) || MULTILINE_REGEXP.test(received)); | ||
} | ||
if ( | ||
expectedType === 'date' || | ||
expectedType === 'function' || | ||
expectedType === 'regexp' | ||
) { | ||
if (expectedType === 'date' || expectedType === 'function' || expectedType === 'regexp') { | ||
return false; | ||
@@ -288,6 +376,3 @@ } | ||
} | ||
if ( | ||
receivedType === 'object' && | ||
typeof received.asymmetricMatch === 'function' | ||
) { | ||
if (receivedType === 'object' && typeof received.asymmetricMatch === 'function') { | ||
return false; | ||
@@ -297,19 +382,6 @@ } | ||
}; | ||
const MAX_DIFF_STRING_LENGTH = 20000; | ||
const printDiffOrStringify = ( | ||
expected, | ||
received, | ||
expectedLabel, | ||
receivedLabel, | ||
expand // CLI options: true if `--expand` or false if `--no-expand` | ||
const MAX_DIFF_STRING_LENGTH = 20_000; | ||
const printDiffOrStringify = (expected, received, expectedLabel, receivedLabel, expand // CLI options: true if `--expand` or false if `--no-expand` | ||
) => { | ||
if ( | ||
typeof expected === 'string' && | ||
typeof received === 'string' && | ||
expected.length !== 0 && | ||
received.length !== 0 && | ||
expected.length <= MAX_DIFF_STRING_LENGTH && | ||
received.length <= MAX_DIFF_STRING_LENGTH && | ||
expected !== received | ||
) { | ||
if (typeof expected === 'string' && typeof received === 'string' && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) { | ||
if (expected.includes('\n') || received.includes('\n')) { | ||
@@ -330,25 +402,11 @@ return (0, _jestDiff.diffStringsUnified)(expected, received, { | ||
const printLabel = getLabelPrinter(expectedLabel, receivedLabel); | ||
const expectedLine = | ||
printLabel(expectedLabel) + | ||
printExpected( | ||
getCommonAndChangedSubstrings( | ||
diffs, | ||
_jestDiff.DIFF_DELETE, | ||
hasCommonDiff | ||
) | ||
); | ||
const receivedLine = | ||
printLabel(receivedLabel) + | ||
printReceived( | ||
getCommonAndChangedSubstrings( | ||
diffs, | ||
_jestDiff.DIFF_INSERT, | ||
hasCommonDiff | ||
) | ||
); | ||
const expectedLine = printLabel(expectedLabel) + printExpected(getCommonAndChangedSubstrings(diffs, _jestDiff.DIFF_DELETE, hasCommonDiff)); | ||
const receivedLine = printLabel(receivedLabel) + printReceived(getCommonAndChangedSubstrings(diffs, _jestDiff.DIFF_INSERT, hasCommonDiff)); | ||
return `${expectedLine}\n${receivedLine}`; | ||
} | ||
if (isLineDiffable(expected, received)) { | ||
const {replacedExpected, replacedReceived} = | ||
replaceMatchedToAsymmetricMatcher(expected, received, [], []); | ||
const { | ||
replacedExpected, | ||
replacedReceived | ||
} = replaceMatchedToAsymmetricMatcher(expected, received, [], []); | ||
const difference = (0, _jestDiff.diff)(replacedExpected, replacedReceived, { | ||
@@ -360,7 +418,3 @@ aAnnotation: expectedLabel, | ||
}); | ||
if ( | ||
typeof difference === 'string' && | ||
difference.includes(`- ${expectedLabel}`) && | ||
difference.includes(`+ ${receivedLabel}`) | ||
) { | ||
if (typeof difference === 'string' && difference.includes(`- ${expectedLabel}`) && difference.includes(`+ ${receivedLabel}`)) { | ||
return difference; | ||
@@ -371,7 +425,3 @@ } | ||
const expectedLine = printLabel(expectedLabel) + printExpected(expected); | ||
const receivedLine = | ||
printLabel(receivedLabel) + | ||
(stringify(expected) === stringify(received) | ||
? 'serializes to the same string' | ||
: printReceived(received)); | ||
const receivedLine = printLabel(receivedLabel) + (stringify(expected) === stringify(received) ? 'serializes to the same string' : printReceived(received)); | ||
return `${expectedLine}\n${receivedLine}`; | ||
@@ -396,21 +446,6 @@ }; | ||
}; | ||
function replaceMatchedToAsymmetricMatcher( | ||
replacedExpected, | ||
replacedReceived, | ||
expectedCycles, | ||
receivedCycles | ||
) { | ||
return _replaceMatchedToAsymmetricMatcher( | ||
(0, _deepCyclicCopyReplaceable.default)(replacedExpected), | ||
(0, _deepCyclicCopyReplaceable.default)(replacedReceived), | ||
expectedCycles, | ||
receivedCycles | ||
); | ||
function replaceMatchedToAsymmetricMatcher(replacedExpected, replacedReceived, expectedCycles, receivedCycles) { | ||
return _replaceMatchedToAsymmetricMatcher((0, _deepCyclicCopyReplaceable.default)(replacedExpected), (0, _deepCyclicCopyReplaceable.default)(replacedReceived), expectedCycles, receivedCycles); | ||
} | ||
function _replaceMatchedToAsymmetricMatcher( | ||
replacedExpected, | ||
replacedReceived, | ||
expectedCycles, | ||
receivedCycles | ||
) { | ||
function _replaceMatchedToAsymmetricMatcher(replacedExpected, replacedReceived, expectedCycles, receivedCycles) { | ||
if (!_Replaceable.default.isReplaceable(replacedExpected, replacedReceived)) { | ||
@@ -422,6 +457,3 @@ return { | ||
} | ||
if ( | ||
expectedCycles.includes(replacedExpected) || | ||
receivedCycles.includes(replacedReceived) | ||
) { | ||
if (expectedCycles.includes(replacedExpected) || receivedCycles.includes(replacedReceived)) { | ||
return { | ||
@@ -436,2 +468,4 @@ replacedExpected, | ||
const receivedReplaceable = new _Replaceable.default(replacedReceived); | ||
// eslint-disable-next-line unicorn/no-array-for-each | ||
expectedReplaceable.forEach((expectedValue, key) => { | ||
@@ -447,11 +481,4 @@ const receivedValue = receivedReplaceable.get(key); | ||
} | ||
} else if ( | ||
_Replaceable.default.isReplaceable(expectedValue, receivedValue) | ||
) { | ||
const replaced = _replaceMatchedToAsymmetricMatcher( | ||
expectedValue, | ||
receivedValue, | ||
expectedCycles, | ||
receivedCycles | ||
); | ||
} else if (_Replaceable.default.isReplaceable(expectedValue, receivedValue)) { | ||
const replaced = _replaceMatchedToAsymmetricMatcher(expectedValue, receivedValue, expectedCycles, receivedCycles); | ||
expectedReplaceable.set(key, replaced.replacedExpected); | ||
@@ -470,7 +497,5 @@ receivedReplaceable.set(key, replaced.replacedReceived); | ||
} | ||
const diff = (a, b, options) => | ||
shouldPrintDiff(a, b) ? (0, _jestDiff.diff)(a, b, options) : null; | ||
const diff = (a, b, options) => shouldPrintDiff(a, b) ? (0, _jestDiff.diff)(a, b, options) : null; | ||
exports.diff = diff; | ||
const pluralize = (word, count) => | ||
`${NUMBERS[count] || count} ${word}${count === 1 ? '' : 's'}`; | ||
const pluralize = (word, count) => `${NUMBERS[count] || count} ${word}${count === 1 ? '' : 's'}`; | ||
@@ -483,17 +508,8 @@ // To display lines of labeled values as two columns with monospace alignment: | ||
const getLabelPrinter = (...strings) => { | ||
const maxLength = strings.reduce( | ||
(max, string) => (string.length > max ? string.length : max), | ||
0 | ||
); | ||
const maxLength = strings.reduce((max, string) => string.length > max ? string.length : max, 0); | ||
return string => `${string}: ${' '.repeat(maxLength - string.length)}`; | ||
}; | ||
exports.getLabelPrinter = getLabelPrinter; | ||
const matcherErrorMessage = ( | ||
hint, | ||
generic, | ||
specific // incorrect value returned from call to printWithType | ||
) => | ||
`${hint}\n\n${_chalk.default.bold('Matcher error')}: ${generic}${ | ||
typeof specific === 'string' ? `\n\n${specific}` : '' | ||
}`; | ||
const matcherErrorMessage = (hint, generic, specific // incorrect value returned from call to printWithType | ||
) => `${hint}\n\n${_chalk.default.bold('Matcher error')}: ${generic}${typeof specific === 'string' ? `\n\n${specific}` : ''}`; | ||
@@ -504,8 +520,3 @@ // Display assertion for the report when a test fails. | ||
exports.matcherErrorMessage = matcherErrorMessage; | ||
const matcherHint = ( | ||
matcherName, | ||
received = 'received', | ||
expected = 'expected', | ||
options = {} | ||
) => { | ||
const matcherHint = (matcherName, received = 'received', expected = 'expected', options = {}) => { | ||
const { | ||
@@ -564,1 +575,6 @@ comment = '', | ||
exports.matcherHint = matcherHint; | ||
})(); | ||
module.exports = __webpack_exports__; | ||
/******/ })() | ||
; |
{ | ||
"name": "jest-matcher-utils", | ||
"description": "A set of utility functions for expect and related packages", | ||
"version": "29.7.0", | ||
"version": "30.0.0-alpha.1", | ||
"repository": { | ||
@@ -11,3 +11,3 @@ "type": "git", | ||
"engines": { | ||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0" | ||
"node": "^16.10.0 || ^18.12.0 || >=20.0.0" | ||
}, | ||
@@ -20,2 +20,4 @@ "license": "MIT", | ||
"types": "./build/index.d.ts", | ||
"require": "./build/index.js", | ||
"import": "./build/index.mjs", | ||
"default": "./build/index.js" | ||
@@ -27,8 +29,8 @@ }, | ||
"chalk": "^4.0.0", | ||
"jest-diff": "^29.7.0", | ||
"jest-get-type": "^29.6.3", | ||
"pretty-format": "^29.7.0" | ||
"jest-diff": "30.0.0-alpha.1", | ||
"jest-get-type": "30.0.0-alpha.1", | ||
"pretty-format": "30.0.0-alpha.1" | ||
}, | ||
"devDependencies": { | ||
"@jest/test-utils": "^29.7.0", | ||
"@jest/test-utils": "30.0.0-alpha.1", | ||
"@types/node": "*" | ||
@@ -39,3 +41,3 @@ }, | ||
}, | ||
"gitHead": "4e56991693da7cd4c3730dc3579a1dd1403ee630" | ||
"gitHead": "d005cb2505c041583e0c5636d006e08666a54b63" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
30751
6
661
2
+ Added@jest/schemas@30.0.0-alpha.1(transitive)
+ Added@sinclair/typebox@0.31.28(transitive)
+ Addeddiff-sequences@30.0.0-alpha.1(transitive)
+ Addedjest-diff@30.0.0-alpha.1(transitive)
+ Addedjest-get-type@30.0.0-alpha.1(transitive)
+ Addedpretty-format@30.0.0-alpha.1(transitive)
+ Addedreact-is@18.3.1(transitive)
- Removed@jest/schemas@29.6.3(transitive)
- Removed@sinclair/typebox@0.27.8(transitive)
- Removeddiff-sequences@29.6.3(transitive)
- Removedjest-diff@29.7.0(transitive)
- Removedjest-get-type@29.6.3(transitive)
- Removedpretty-format@29.7.0(transitive)
- Removedreact-is@18.3.0(transitive)
Updatedjest-diff@30.0.0-alpha.1
Updatedjest-get-type@30.0.0-alpha.1
Updatedpretty-format@30.0.0-alpha.1