New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jest-matchers

Package Overview
Dependencies
Maintainers
3
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-matchers - npm Package Compare versions

Comparing version 19.0.0 to 19.1.0-alpha.eed82034

25

build/asymmetric-matchers.js

@@ -19,5 +19,4 @@ /**

require('./jasmine-utils');const equals = _require.equals,fnNameFor = _require.fnNameFor,hasProperty = _require.hasProperty,isA = _require.isA,isUndefined = _require.isUndefined;
require('./jasmine-utils');const contains = _require.contains,equals = _require.equals,fnNameFor = _require.fnNameFor,hasProperty = _require.hasProperty,isA = _require.isA,isUndefined = _require.isUndefined;
class AsymmetricMatcher {

@@ -129,15 +128,12 @@

throw new Error(
'You must provide an array to ArrayContaining, not \'' +
typeof this.sample + '\'.');
"You must provide an array to ArrayContaining, not '" +
typeof this.sample +
"'.");
}
for (let i = 0; i < this.sample.length; i++) {
const item = this.sample[i];
if (!contains(other, item)) {
return false;
}
}
return true;
return this.sample.length === 0 ||
Array.isArray(other) &&
this.sample.every(item =>
other.some(another => equals(item, another)));
}

@@ -165,4 +161,5 @@

throw new Error(
'You must provide an object to ObjectContaining, not \'' +
typeof this.sample + '\'.');
"You must provide an object to ObjectContaining, not '" +
typeof this.sample +
"'.");

@@ -169,0 +166,0 @@ }

@@ -11,3 +11,3 @@ /**

'use strict';
'use strict';function _asyncToGenerator(fn) {return function () {var gen = fn.apply(this, arguments);return new Promise(function (resolve, reject) {function step(key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {return Promise.resolve(value).then(function (value) {step("next", value);}, function (err) {step("throw", err);});}}return step("next");});};}

@@ -25,2 +25,3 @@

const matchers = require('./matchers');

@@ -46,11 +47,15 @@ const spyMatchers = require('./spyMatchers');

const isPromise = obj => {
return !!obj && (
typeof obj === 'object' || typeof obj === 'function') &&
typeof obj.then === 'function';
};
if (!global[GLOBAL_STATE]) {
Object.defineProperty(
global,
GLOBAL_STATE,
{ value: {
Object.defineProperty(global, GLOBAL_STATE, {
value: {
matchers: Object.create(null),
state: {
assertionCalls: 0,
assertionsExpected: null,
assertionsMade: 0,
suppressedErrors: [] } } });

@@ -64,8 +69,41 @@

const allMatchers = global[GLOBAL_STATE].matchers;
const expectation = { not: {} };
const expectation = {
not: {},
rejects: { not: {} },
resolves: { not: {} } };
Object.keys(allMatchers).forEach(name => {
expectation[name] =
makeThrowingMatcher(allMatchers[name], false, actual);
expectation.not[name] =
makeThrowingMatcher(allMatchers[name], true, actual);
expectation[name] = makeThrowingMatcher(allMatchers[name], false, actual);
expectation.not[name] = makeThrowingMatcher(
allMatchers[name],
true,
actual);
expectation.resolves[name] = makeResolveMatcher(
name,
allMatchers[name],
false,
actual);
expectation.resolves.not[name] = makeResolveMatcher(
name,
allMatchers[name],
true,
actual);
expectation.rejects[name] = makeRejectMatcher(
name,
allMatchers[name],
false,
actual);
expectation.rejects.not[name] = makeRejectMatcher(
name,
allMatchers[name],
true,
actual);
});

@@ -91,2 +129,67 @@

const makeResolveMatcher = (
matcherName,
matcher,
isNot,
actual) => _asyncToGenerator(
function* () {for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
const matcherStatement = `.resolves.${isNot ? 'not.' : ''}${matcherName}`;
if (!isPromise(actual)) {
throw new JestAssertionError(
utils.matcherHint(matcherStatement, 'received', '') +
'\n\n' +
`${utils.RECEIVED_COLOR('received')} value must be a Promise.\n` +
utils.printWithType('Received', actual, utils.printReceived));
}
let result;
try {
result = yield actual;
} catch (e) {
throw new JestAssertionError(
utils.matcherHint(matcherStatement, 'received', '') +
'\n\n' +
`Expected ${utils.RECEIVED_COLOR('received')} Promise to resolve, ` +
'instead it rejected to value\n' +
` ${utils.printReceived(e)}`);
}
return makeThrowingMatcher(matcher, isNot, result).apply(null, args);
});
const makeRejectMatcher = (
matcherName,
matcher,
isNot,
actual) => _asyncToGenerator(
function* () {for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {args[_key2] = arguments[_key2];}
const matcherStatement = `.rejects.${isNot ? 'not.' : ''}${matcherName}`;
if (!isPromise(actual)) {
throw new JestAssertionError(
utils.matcherHint(matcherStatement, 'received', '') +
'\n\n' +
`${utils.RECEIVED_COLOR('received')} value must be a Promise.\n` +
utils.printWithType('Received', actual, utils.printReceived));
}
let result;
try {
result = yield actual;
} catch (e) {
return makeThrowingMatcher(matcher, isNot, e).apply(null, args);
}
throw new JestAssertionError(
utils.matcherHint(matcherStatement, 'received', '') +
'\n\n' +
`Expected ${utils.RECEIVED_COLOR('received')} Promise to reject, ` +
'instead it resolved to value\n' +
` ${utils.printReceived(result)}`);
});
const makeThrowingMatcher = (

@@ -114,7 +217,4 @@ matcher,

try {for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
result = matcher.apply(
matcherContext,
[actual].concat(args));
try {for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {args[_key3] = arguments[_key3];}
result = matcher.apply(matcherContext, [actual].concat(args));
} catch (error) {

@@ -128,5 +228,6 @@ // Remove this and deeper functions from the stack trace frame.

global[GLOBAL_STATE].state.assertionsMade++;
global[GLOBAL_STATE].state.assertionCalls++;
if (result.pass && isNot || !result.pass && !isNot) {// XOR
if (result.pass && isNot || !result.pass && !isNot) {
// XOR
const message = getMessage(result.message);

@@ -165,9 +266,5 @@ const error = new JestAssertionError(message);

typeof result.pass !== 'boolean' ||
result.message &&
typeof result.message !== 'string' &&
typeof result.message !== 'function')
{

@@ -192,3 +289,2 @@ throw new Error(

expect.setState = state => {

@@ -195,0 +291,0 @@ Object.assign(global[GLOBAL_STATE].state, state);

@@ -34,19 +34,2 @@ /*

function contains(haystack, needle, customTesters) {
customTesters = customTesters || [];
if (Object.prototype.toString.apply(haystack) === '[object Array]' ||
!!haystack && !haystack.indexOf)
{
for (var i = 0; i < haystack.length; i++) {
if (eq(haystack[i], needle, [], [], customTesters)) {
return true;
}
}
return false;
}
return !!haystack && haystack.indexOf(needle) >= 0;
}
function isAsymmetric(obj) {

@@ -57,4 +40,3 @@ return obj && isA('Function', obj.asymmetricMatch);

function asymmetricMatch(a, b) {
var asymmetricA = isAsymmetric(a),
asymmetricB = isAsymmetric(b);
var asymmetricA = isAsymmetric(a),asymmetricB = isAsymmetric(b);

@@ -97,7 +79,13 @@ if (asymmetricA && asymmetricB) {

// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
if (a === b) {return a !== 0 || 1 / a == 1 / b;}
if (a === b) {
return a !== 0 || 1 / a == 1 / b;
}
// A strict comparison is necessary because `null == undefined`.
if (a === null || b === null) {return a === b;}
if (a === null || b === null) {
return a === b;
}
var className = Object.prototype.toString.call(a);
if (className != Object.prototype.toString.call(b)) {return false;}
if (className != Object.prototype.toString.call(b)) {
return false;
}
switch (className) {

@@ -126,3 +114,5 @@ // Strings, numbers, dates, and booleans are compared by value.

if (typeof a != 'object' || typeof b != 'object') {return false;}
if (typeof a != 'object' || typeof b != 'object') {
return false;
}

@@ -157,3 +147,5 @@ var aIsDomNode = isDomNode(a);

// unique nested structures.
if (aStack[length] == a) {return bStack[length] == b;}
if (aStack[length] == a) {
return bStack[length] == b;
}
}

@@ -190,3 +182,2 @@ // Add the first object to the stack of traversed objects.

} // Objects with different constructors are not equivalent, but `Object`s

@@ -204,3 +195,5 @@ // or `Array`s from different frames are.

var aKeys = keys(a, className == '[object Array]'),key;size = aKeys.length; // Ensure that both objects contain the same number of properties before comparing deep equality.
if (keys(b, className == '[object Array]').length !== size) {return false;}while (size--) {key = aKeys[size]; // Deep compare each member
if (keys(b, className == '[object Array]').length !== size) {return false;}while (size--) {key = aKeys[size];
// Deep compare each member
result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters);

@@ -252,3 +245,4 @@

// TODO(cpojer): remove the `obj[key] !== undefined` check.
return Object.prototype.hasOwnProperty.call(obj, key) && obj[key] !== undefined;
return Object.prototype.hasOwnProperty.call(obj, key) &&
obj[key] !== undefined;
}

@@ -302,3 +296,2 @@

module.exports = {
contains,
equals,

@@ -305,0 +298,0 @@ fnNameFor,

@@ -16,4 +16,2 @@ /**

const diff = require('jest-diff');var _require =

@@ -47,3 +45,2 @@ require('jest-regex-util');const escapeStrForRegex = _require.escapeStrForRegex;var _require2 =

const IteratorSymbol = Symbol.iterator;

@@ -70,10 +67,3 @@

const nextB = bIterator.next();
if (
nextB.done ||
!equals(
aValue,
nextB.value,
[iterableEquality]))
{
if (nextB.done || !equals(aValue, nextB.value, [iterableEquality])) {
return false;

@@ -87,4 +77,7 @@ }

};
const isObjectWithKeys = a => a !== null && typeof a === 'object' &&
!(a instanceof Array) && !(a instanceof Date);
const isObjectWithKeys = a =>
a !== null &&
typeof a === 'object' &&
!(a instanceof Array) &&
!(a instanceof Date);
const subsetEquality = (object, subset) => {

@@ -94,3 +87,4 @@ if (!isObjectWithKeys(object) || !isObjectWithKeys(subset)) {

}
return Object.keys(subset).every(key =>
return Object.keys(subset).every(
key =>
object.hasOwnProperty(key) &&

@@ -106,3 +100,5 @@ equals(object[key], subset[key], [iterableEquality, subsetEquality]));

const message = pass ?
() => matcherHint('.not.toBe') + '\n\n' +
() =>
matcherHint('.not.toBe') +
'\n\n' +
`Expected value to not be (using ===):\n` +

@@ -116,3 +112,4 @@ ` ${printExpected(expected)}\n` +

return matcherHint('.toBe') + '\n\n' +
return matcherHint('.toBe') +
'\n\n' +
`Expected value to be (using ===):\n` +

@@ -131,11 +128,9 @@ ` ${printExpected(expected)}\n` +

toBeCloseTo(
actual,
expected)
{let precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
toBeCloseTo(actual, expected) {let precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
ensureNumbers(actual, expected, '.toBeCloseTo');
const pass = Math.abs(expected - actual) < Math.pow(10, -precision) / 2;
const message = pass ?
() => matcherHint('.not.toBeCloseTo', 'received', 'expected, precision') + '\n\n' +
() =>
matcherHint('.not.toBeCloseTo', 'received', 'expected, precision') +
'\n\n' +
`Expected value not to be close to (with ${printExpected(precision)}-digit precision):\n` +

@@ -145,3 +140,5 @@ ` ${printExpected(expected)}\n` +

` ${printReceived(actual)}` :
() => matcherHint('.toBeCloseTo', 'received', 'expected, precision') + '\n\n' +
() =>
matcherHint('.toBeCloseTo', 'received', 'expected, precision') +
'\n\n' +
`Expected value to be close to (with ${printExpected(precision)}-digit precision):\n` +

@@ -159,6 +156,10 @@ ` ${printExpected(expected)}\n` +

const message = pass ?
() => matcherHint('.not.toBeDefined', 'received', '') + '\n\n' +
() =>
matcherHint('.not.toBeDefined', 'received', '') +
'\n\n' +
`Expected value not to be defined, instead received\n` +
` ${printReceived(actual)}` :
() => matcherHint('.toBeDefined', 'received', '') + '\n\n' +
() =>
matcherHint('.toBeDefined', 'received', '') +
'\n\n' +
`Expected value to be defined, instead received\n` +

@@ -173,6 +174,10 @@ ` ${printReceived(actual)}`;

const message = pass ?
() => matcherHint('.not.toBeFalsy', 'received', '') + '\n\n' +
() =>
matcherHint('.not.toBeFalsy', 'received', '') +
'\n\n' +
`Expected value not to be falsy, instead received\n` +
` ${printReceived(actual)}` :
() => matcherHint('.toBeFalsy', 'received', '') + '\n\n' +
() =>
matcherHint('.toBeFalsy', 'received', '') +
'\n\n' +
`Expected value to be falsy, instead received\n` +

@@ -187,3 +192,5 @@ ` ${printReceived(actual)}`;

const message = pass ?
() => matcherHint('.not.toBeGreaterThan') + '\n\n' +
() =>
matcherHint('.not.toBeGreaterThan') +
'\n\n' +
`Expected value not to be greater than:\n` +

@@ -193,3 +200,5 @@ ` ${printExpected(expected)}\n` +

` ${printReceived(actual)}` :
() => matcherHint('.toBeGreaterThan') + '\n\n' +
() =>
matcherHint('.toBeGreaterThan') +
'\n\n' +
`Expected value to be greater than:\n` +

@@ -206,3 +215,5 @@ ` ${printExpected(expected)}\n` +

const message = pass ?
() => matcherHint('.not.toBeGreaterThanOrEqual') + '\n\n' +
() =>
matcherHint('.not.toBeGreaterThanOrEqual') +
'\n\n' +
`Expected value not to be greater than or equal:\n` +

@@ -212,3 +223,5 @@ ` ${printExpected(expected)}\n` +

` ${printReceived(actual)}` :
() => matcherHint('.toBeGreaterThanOrEqual') + '\n\n' +
() =>
matcherHint('.toBeGreaterThanOrEqual') +
'\n\n' +
`Expected value to be greater than or equal:\n` +

@@ -226,3 +239,4 @@ ` ${printExpected(expected)}\n` +

throw new Error(
matcherHint('[.not].toBeInstanceOf', 'value', 'constructor') + `\n\n` +
matcherHint('[.not].toBeInstanceOf', 'value', 'constructor') +
`\n\n` +
`Expected constructor to be a function. Instead got:\n` +

@@ -235,3 +249,5 @@ ` ${printExpected(constType)}`);

const message = pass ?
() => matcherHint('.not.toBeInstanceOf', 'value', 'constructor') + '\n\n' +
() =>
matcherHint('.not.toBeInstanceOf', 'value', 'constructor') +
'\n\n' +
`Expected value not to be an instance of:\n` +

@@ -241,3 +257,5 @@ ` ${printExpected(constructor.name || constructor)}\n` +

` ${printReceived(received)}\n` :
() => matcherHint('.toBeInstanceOf', 'value', 'constructor') + '\n\n' +
() =>
matcherHint('.toBeInstanceOf', 'value', 'constructor') +
'\n\n' +
`Expected value to be an instance of:\n` +

@@ -257,3 +275,5 @@ ` ${printExpected(constructor.name || constructor)}\n` +

const message = pass ?
() => matcherHint('.not.toBeLessThan') + '\n\n' +
() =>
matcherHint('.not.toBeLessThan') +
'\n\n' +
`Expected value not to be less than:\n` +

@@ -263,3 +283,5 @@ ` ${printExpected(expected)}\n` +

` ${printReceived(actual)}` :
() => matcherHint('.toBeLessThan') + '\n\n' +
() =>
matcherHint('.toBeLessThan') +
'\n\n' +
`Expected value to be less than:\n` +

@@ -276,3 +298,5 @@ ` ${printExpected(expected)}\n` +

const message = pass ?
() => matcherHint('.not.toBeLessThanOrEqual') + '\n\n' +
() =>
matcherHint('.not.toBeLessThanOrEqual') +
'\n\n' +
`Expected value not to be less than or equal:\n` +

@@ -282,3 +306,5 @@ ` ${printExpected(expected)}\n` +

` ${printReceived(actual)}` :
() => matcherHint('.toBeLessThanOrEqual') + '\n\n' +
() =>
matcherHint('.toBeLessThanOrEqual') +
'\n\n' +
`Expected value to be less than or equal:\n` +

@@ -295,6 +321,10 @@ ` ${printExpected(expected)}\n` +

const message = pass ?
() => matcherHint('.not.toBeNaN', 'received', '') + '\n\n' +
() =>
matcherHint('.not.toBeNaN', 'received', '') +
'\n\n' +
`Expected value not to be NaN, instead received\n` +
` ${printReceived(actual)}` :
() => matcherHint('.toBeNaN', 'received', '') + '\n\n' +
() =>
matcherHint('.toBeNaN', 'received', '') +
'\n\n' +
`Expected value to be NaN, instead received\n` +

@@ -309,6 +339,10 @@ ` ${printReceived(actual)}`;

const message = pass ?
() => matcherHint('.not.toBeNull', 'received', '') + '\n\n' +
() =>
matcherHint('.not.toBeNull', 'received', '') +
'\n\n' +
`Expected value not to be null, instead received\n` +
` ${printReceived(actual)}` :
() => matcherHint('.toBeNull', 'received', '') + '\n\n' +
() =>
matcherHint('.toBeNull', 'received', '') +
'\n\n' +
`Expected value to be null, instead received\n` +

@@ -323,6 +357,10 @@ ` ${printReceived(actual)}`;

const message = pass ?
() => matcherHint('.not.toBeTruthy', 'received', '') + '\n\n' +
() =>
matcherHint('.not.toBeTruthy', 'received', '') +
'\n\n' +
`Expected value not to be truthy, instead received\n` +
` ${printReceived(actual)}` :
() => matcherHint('.toBeTruthy', 'received', '') + '\n\n' +
() =>
matcherHint('.toBeTruthy', 'received', '') +
'\n\n' +
`Expected value to be truthy, instead received\n` +

@@ -337,6 +375,10 @@ ` ${printReceived(actual)}`;

const message = pass ?
() => matcherHint('.not.toBeUndefined', 'received', '') + '\n\n' +
() =>
matcherHint('.not.toBeUndefined', 'received', '') +
'\n\n' +
`Expected value not to be undefined, instead received\n` +
` ${printReceived(actual)}` :
() => matcherHint('.toBeUndefined', 'received', '') + '\n\n' +
() =>
matcherHint('.toBeUndefined', 'received', '') +
'\n\n' +
`Expected value to be undefined, instead received\n` +

@@ -361,3 +403,4 @@ ` ${printReceived(actual)}`;

throw new Error(
matcherHint('[.not].toContainEqual', 'collection', 'value') + '\n\n' +
matcherHint('[.not].toContainEqual', 'collection', 'value') +
'\n\n' +
`Expected ${RECEIVED_COLOR('collection')} to be an array-like structure.\n` +

@@ -372,3 +415,5 @@ printWithType('Received', collection, printReceived));

const message = pass ?
() => matcherHint('.not.toContain', collectionType, 'value') + '\n\n' +
() =>
matcherHint('.not.toContain', collectionType, 'value') +
'\n\n' +
`Expected ${collectionType}:\n` +

@@ -378,3 +423,5 @@ ` ${printReceived(collection)}\n` +

` ${printExpected(value)}\n` :
() => matcherHint('.toContain', collectionType, 'value') + '\n\n' +
() =>
matcherHint('.toContain', collectionType, 'value') +
'\n\n' +
`Expected ${collectionType}:\n` +

@@ -398,3 +445,4 @@ ` ${printReceived(collection)}\n` +

throw new Error(
matcherHint('[.not].toContainEqual', 'collection', 'value') + '\n\n' +
matcherHint('[.not].toContainEqual', 'collection', 'value') +
'\n\n' +
`Expected ${RECEIVED_COLOR('collection')} to be an array-like structure.\n` +

@@ -406,6 +454,8 @@ printWithType('Received', collection, printReceived));

const pass =
converted.findIndex(item => equals(item, value, [iterableEquality])) !== -1;
const pass = converted.findIndex(item =>
equals(item, value, [iterableEquality])) !== -1;
const message = pass ?
() => matcherHint('.not.toContainEqual', collectionType, 'value') + '\n\n' +
() =>
matcherHint('.not.toContainEqual', collectionType, 'value') +
'\n\n' +
`Expected ${collectionType}:\n` +

@@ -415,3 +465,5 @@ ` ${printReceived(collection)}\n` +

` ${printExpected(value)}\n` :
() => matcherHint('.toContainEqual', collectionType, 'value') + '\n\n' +
() =>
matcherHint('.toContainEqual', collectionType, 'value') +
'\n\n' +
`Expected ${collectionType}:\n` +

@@ -429,3 +481,5 @@ ` ${printReceived(collection)}\n` +

const message = pass ?
() => matcherHint('.not.toEqual') + '\n\n' +
() =>
matcherHint('.not.toEqual') +
'\n\n' +
`Expected value to not equal:\n` +

@@ -439,3 +493,4 @@ ` ${printExpected(expected)}\n` +

return matcherHint('.toEqual') + '\n\n' +
return matcherHint('.toEqual') +
'\n\n' +
`Expected value to equal:\n` +

@@ -460,7 +515,7 @@ ` ${printExpected(expected)}\n` +

throw new Error(
matcherHint('[.not].toHaveLength', 'received', 'length') + '\n\n' +
matcherHint('[.not].toHaveLength', 'received', 'length') +
'\n\n' +
`Expected value to have a 'length' property that is a number. ` +
`Received:\n` +
` ${printReceived(received)}\n` + (
received ?

@@ -470,3 +525,2 @@ `received.length:\n ${printReceived(received.length)}` :

}

@@ -476,3 +530,5 @@

const message = pass ?
() => matcherHint('.not.toHaveLength', 'received', 'length') + '\n\n' +
() =>
matcherHint('.not.toHaveLength', 'received', 'length') +
'\n\n' +
`Expected value to not have length:\n` +

@@ -484,3 +540,5 @@ ` ${printExpected(length)}\n` +

` ${printReceived(received.length)}` :
() => matcherHint('.toHaveLength', 'received', 'length') + '\n\n' +
() =>
matcherHint('.toHaveLength', 'received', 'length') +
'\n\n' +
`Expected value to have length:\n` +

@@ -496,3 +554,3 @@ ` ${printExpected(length)}\n` +

toHaveProperty(object, propPath, value) {
toHaveProperty(object, keyPath, value) {
const valuePassed = arguments.length === 3;

@@ -502,3 +560,6 @@

throw new Error(
matcherHint('[.not].toHaveProperty', 'object', 'path', { secondArgument: valuePassed ? 'value' : null }) + '\n\n' +
matcherHint('[.not].toHaveProperty', 'object', 'path', {
secondArgument: valuePassed ? 'value' : null }) +
'\n\n' +
`Expected ${RECEIVED_COLOR('object')} to be an object. Received:\n` +

@@ -509,11 +570,14 @@ ` ${getType(object)}: ${printReceived(object)}`);

if (getType(propPath) !== 'string') {
if (getType(keyPath) !== 'string') {
throw new Error(
matcherHint('[.not].toHaveProperty', 'object', 'path', { secondArgument: valuePassed ? 'value' : null }) + '\n\n' +
matcherHint('[.not].toHaveProperty', 'object', 'path', {
secondArgument: valuePassed ? 'value' : null }) +
'\n\n' +
`Expected ${EXPECTED_COLOR('path')} to be a string. Received:\n` +
` ${getType(propPath)}: ${printReceived(propPath)}`);
` ${getType(keyPath)}: ${printReceived(keyPath)}`);
}
const result = getPath(object, propPath);const
const result = getPath(object, keyPath);const
lastTraversedObject = result.lastTraversedObject,hasEndProp = result.hasEndProp;

@@ -541,15 +605,23 @@

const message = pass ?
matcherHint('.not.toHaveProperty', 'object', 'path', { secondArgument: valuePassed ? 'value' : null }) + '\n\n' +
matcherHint('.not.toHaveProperty', 'object', 'path', {
secondArgument: valuePassed ? 'value' : null }) +
'\n\n' +
`Expected the object:\n` +
` ${printReceived(object)}\n` +
`Not to have a nested property:\n` +
` ${printExpected(propPath)}\n` + (
` ${printExpected(keyPath)}\n` + (
valuePassed ? `With a value of:\n ${printExpected(value)}\n` : '') :
matcherHint('.toHaveProperty', 'object', 'path', { secondArgument: valuePassed ? 'value' : null }) + '\n\n' +
matcherHint('.toHaveProperty', 'object', 'path', {
secondArgument: valuePassed ? 'value' : null }) +
'\n\n' +
`Expected the object:\n` +
` ${printReceived(object)}\n` +
`To have a nested property:\n` +
` ${printExpected(propPath)}\n` + (
` ${printExpected(keyPath)}\n` + (
valuePassed ? `With a value of:\n ${printExpected(value)}\n` : '') + (
traversedPath ? `Received:\n ${RECEIVED_COLOR('object')}.${traversedPath}: ${printReceived(lastTraversedObject)}` : '') + (
traversedPath ?
`Received:\n ${RECEIVED_COLOR('object')}.${traversedPath}: ${printReceived(lastTraversedObject)}` :
'') + (
diffString ? `\nDifference:\n\n${diffString}` : '');

@@ -566,3 +638,4 @@ if (pass === undefined) {

throw new Error(
matcherHint('[.not].toMatch', 'string', 'expected') + '\n\n' +
matcherHint('[.not].toMatch', 'string', 'expected') +
'\n\n' +
`${RECEIVED_COLOR('string')} value must be a string.\n` +

@@ -575,3 +648,4 @@ printWithType('Received', received, printReceived));

throw new Error(
matcherHint('[.not].toMatch', 'string', 'expected') + '\n\n' +
matcherHint('[.not].toMatch', 'string', 'expected') +
'\n\n' +
`${EXPECTED_COLOR('expected')} value must be a string or a regular expression.\n` +

@@ -583,8 +657,7 @@ printWithType('Expected', expected, printExpected));

const pass = new RegExp(
typeof expected === 'string' ?
escapeStrForRegex(expected) :
expected).
typeof expected === 'string' ? escapeStrForRegex(expected) : expected).
test(received);
const message = pass ?
() => matcherHint('.not.toMatch') +
() =>
matcherHint('.not.toMatch') +
`\n\nExpected value not to match:\n` +

@@ -594,3 +667,4 @@ ` ${printExpected(expected)}` +

` ${printReceived(received)}` :
() => matcherHint('.toMatch') +
() =>
matcherHint('.toMatch') +
`\n\nExpected value to match:\n` +

@@ -605,6 +679,6 @@ ` ${printExpected(expected)}` +

toMatchObject(receivedObject, expectedObject) {
if (typeof receivedObject !== 'object' || receivedObject === null) {
throw new Error(
matcherHint('[.not].toMatchObject', 'object', 'expected') + '\n\n' +
matcherHint('[.not].toMatchObject', 'object', 'expected') +
'\n\n' +
`${RECEIVED_COLOR('received')} value must be an object.\n` +

@@ -617,3 +691,4 @@ printWithType('Received', receivedObject, printReceived));

throw new Error(
matcherHint('[.not].toMatchObject', 'object', 'expected') + '\n\n' +
matcherHint('[.not].toMatchObject', 'object', 'expected') +
'\n\n' +
`${EXPECTED_COLOR('expected')} value must be an object.\n` +

@@ -624,6 +699,10 @@ printWithType('Expected', expectedObject, printExpected));

const pass = equals(receivedObject, expectedObject, [iterableEquality, subsetEquality]);
const pass = equals(receivedObject, expectedObject, [
iterableEquality,
subsetEquality]);
const message = pass ?
() => matcherHint('.not.toMatchObject') +
() =>
matcherHint('.not.toMatchObject') +
`\n\nExpected value not to match object:\n` +

@@ -634,5 +713,9 @@ ` ${printExpected(expectedObject)}` +

() => {
const diffString = diff(expectedObject, getObjectSubset(receivedObject, expectedObject), {
const diffString = diff(
expectedObject,
getObjectSubset(receivedObject, expectedObject),
{
expand: this.expand });
return matcherHint('.toMatchObject') +

@@ -639,0 +722,0 @@ `\n\nExpected value to match object:\n` +

@@ -37,3 +37,4 @@ /**

const createToBeCalledMatcher = matcherName => (received, expected) => {
const createToBeCalledMatcher = matcherName =>
(received, expected) => {
ensureNoExpected(expected, matcherName);

@@ -52,7 +53,10 @@ ensureMock(received, matcherName);

const message = pass ?
() => matcherHint('.not' + matcherName, RECEIVED_NAME[type], '') +
() =>
matcherHint('.not' + matcherName, RECEIVED_NAME[type], '') +
'\n\n' +
`Expected ${type} not to be called ` +
formatReceivedCalls(calls, CALL_PRINT_LIMIT, { sameSentence: true }) :
() => matcherHint(matcherName, RECEIVED_NAME[type], '') + '\n\n' +
() =>
matcherHint(matcherName, RECEIVED_NAME[type], '') +
'\n\n' +
`Expected ${type} to have been called.`;

@@ -64,6 +68,3 @@

const createToBeCalledWithMatcher = matcherName =>
function (
received)
{for (var _len = arguments.length, expected = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {expected[_key - 1] = arguments[_key];}
function (received) {for (var _len = arguments.length, expected = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {expected[_key - 1] = arguments[_key];}
ensureMock(received, matcherName);

@@ -79,6 +80,10 @@

const message = pass ?
() => matcherHint('.not' + matcherName, RECEIVED_NAME[type]) + '\n\n' +
() =>
matcherHint('.not' + matcherName, RECEIVED_NAME[type]) +
'\n\n' +
`Expected ${type} not to have been called with:\n` +
` ${printExpected(expected)}` :
() => matcherHint(matcherName, RECEIVED_NAME[type]) + '\n\n' +
() =>
matcherHint(matcherName, RECEIVED_NAME[type]) +
'\n\n' +
`Expected ${type} to have been called with:\n` +

@@ -92,6 +97,3 @@ ` ${printExpected(expected)}\n` +

const createLastCalledWithMatcher = matcherName =>
function (
received)
{for (var _len2 = arguments.length, expected = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {expected[_key2 - 1] = arguments[_key2];}
function (received) {for (var _len2 = arguments.length, expected = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {expected[_key2 - 1] = arguments[_key2];}
ensureMock(received, matcherName);

@@ -107,6 +109,10 @@

const message = pass ?
() => matcherHint('.not' + matcherName, RECEIVED_NAME[type]) + '\n\n' +
() =>
matcherHint('.not' + matcherName, RECEIVED_NAME[type]) +
'\n\n' +
`Expected ${type} to not have been last called with:\n` +
` ${printExpected(expected)}` :
() => matcherHint(matcherName, RECEIVED_NAME[type]) + '\n\n' +
() =>
matcherHint(matcherName, RECEIVED_NAME[type]) +
'\n\n' +
`Expected ${type} to have been last called with:\n` +

@@ -136,5 +142,5 @@ ` ${printExpected(expected)}\n` +

const message = pass ?
() => matcherHint(
'.not' +
matcherName,
() =>
matcherHint(
'.not' + matcherName,
RECEIVED_NAME[type],

@@ -147,3 +153,4 @@ String(expected)) +

` called exactly ${RECEIVED_COLOR(pluralize('time', count))}.` :
() => matcherHint(matcherName, RECEIVED_NAME[type], String(expected)) +
() =>
matcherHint(matcherName, RECEIVED_NAME[type], String(expected)) +
'\n\n' +

@@ -157,6 +164,7 @@ `Expected ${type} to have been called ` +

toHaveBeenCalledWith: createToBeCalledWithMatcher('.toHaveBeenCalledWith'),
toHaveBeenLastCalledWith:
createLastCalledWithMatcher('.toHaveBeenLastCalledWith') };
toHaveBeenLastCalledWith: createLastCalledWithMatcher(
'.toHaveBeenLastCalledWith') };
const isSpy = spy => spy.calls && typeof spy.calls.count === 'function';

@@ -171,4 +179,6 @@

throw new Error(
matcherHint('[.not]' + matcherName, 'jest.fn()', '') + '\n\n' +
`${RECEIVED_COLOR('jest.fn()')} value must be a mock function or spy.\n` +
matcherHint('[.not]' + matcherName, 'jest.fn()', '') +
'\n\n' +
`${RECEIVED_COLOR('jest.fn()')} value must be a mock function ` +
`or spy.\n` +
printWithType('Received', mockOrSpy, printReceived));

@@ -183,4 +193,3 @@

const count = calls.length - limit;
const printedCalls =
calls.
const printedCalls = calls.
slice(-limit).

@@ -190,10 +199,8 @@ reverse().

join(', ');
return (
`${but} it was ${options && options.isLast ? 'last ' : ''}called ` +
`with:\n ` + printedCalls + (
count > 0 ?
'\nand ' + RECEIVED_COLOR(pluralize('more call', count)) + '.' :
''));
return `${but} it was ${options && options.isLast ? 'last ' : ''}called ` +
`with:\n ` +
printedCalls + (
count > 0 ?
'\nand ' + RECEIVED_COLOR(pluralize('more call', count)) + '.' :
'');
} else {

@@ -200,0 +207,0 @@ return `But it was ${RECEIVED_COLOR('not called')}.`;

@@ -41,2 +41,11 @@ /**

if (typeof actual !== 'function') {
throw new Error(
matcherHint(matcherName, 'function', getType(value)) +
'\n\n' +
'Received value must be a function, but instead ' +
`"${getType(actual)}" was found`);
}
try {

@@ -62,6 +71,10 @@ actual();

message: pass ?
() => matcherHint('.not' + matcherName, 'function', '') + '\n\n' +
() =>
matcherHint('.not' + matcherName, 'function', '') +
'\n\n' +
'Expected the function not to throw an error.\n' +
printActualErrorMessage(error) :
() => matcherHint(matcherName, 'function', getType(value)) + '\n\n' +
() =>
matcherHint(matcherName, 'function', getType(value)) +
'\n\n' +
'Expected the function to throw an error.\n' +

@@ -73,3 +86,4 @@ printActualErrorMessage(error),

throw new Error(
matcherHint('.not' + matcherName, 'function', getType(value)) + '\n\n' +
matcherHint('.not' + matcherName, 'function', getType(value)) +
'\n\n' +
'Unexpected argument passed.\nExpected: ' +

@@ -99,7 +113,11 @@ `${printExpected('string')}, ${printExpected('Error (type)')} or ${printExpected('regexp')}.\n` +

const message = pass ?
() => matcherHint('.not' + name, 'function', getType(value)) + '\n\n' +
() =>
matcherHint('.not' + name, 'function', getType(value)) +
'\n\n' +
`Expected the function not to throw an error matching:\n` +
` ${printExpected(value)}\n` +
printActualErrorMessage(error) :
() => matcherHint(name, 'function', getType(value)) + '\n\n' +
() =>
matcherHint(name, 'function', getType(value)) +
'\n\n' +
`Expected the function to throw an error matching:\n` +

@@ -123,7 +141,11 @@ ` ${printExpected(value)}\n` +

const message = pass ?
() => matcherHint('.not' + name, 'function', 'error') + '\n\n' +
() =>
matcherHint('.not' + name, 'function', 'error') +
'\n\n' +
`Expected the function not to throw an error matching:\n` +
` ${printExpected(expectedError)}\n` +
printActualErrorMessage(error) :
() => matcherHint(name, 'function', 'error') + '\n\n' +
() =>
matcherHint(name, 'function', 'error') +
'\n\n' +
`Expected the function to throw an error matching:\n` +

@@ -143,7 +165,11 @@ ` ${printExpected(expectedError)}\n` +

const message = pass ?
() => matcherHint('.not' + name, 'function', 'type') + '\n\n' +
() =>
matcherHint('.not' + name, 'function', 'type') +
'\n\n' +
`Expected the function not to throw an error of type:\n` +
` ${printExpected(ErrorClass.name)}\n` +
printActualErrorMessage(error) :
() => matcherHint(name, 'function', 'type') + '\n\n' +
() =>
matcherHint(name, 'function', 'type') +
'\n\n' +
`Expected the function to throw an error of type:\n` +

@@ -159,14 +185,12 @@ ` ${printExpected(ErrorClass.name)}\n` +

separateMessageFromStack(error.stack);const message = _separateMessageFromS.message,stack = _separateMessageFromS.stack;
return (
`Instead, it threw:\n` +
RECEIVED_COLOR(
' ' +
highlightTrailingWhitespace(message, RECEIVED_BG) +
formatStackTrace(stack, {
noStackTrace: false,
rootDir: process.cwd(),
testMatch: [] })));
return `Instead, it threw:\n` +
RECEIVED_COLOR(
' ' +
highlightTrailingWhitespace(message, RECEIVED_BG) +
formatStackTrace(stack, {
noStackTrace: false,
rootDir: process.cwd(),
testMatch: [] }));
}

@@ -173,0 +197,0 @@

@@ -74,4 +74,6 @@ /**

} else if (
typeof object === 'object' && object !== null &&
typeof subset === 'object' && subset !== null)
typeof object === 'object' &&
object !== null &&
typeof subset === 'object' &&
subset !== null)
{

@@ -90,5 +92,4 @@ const trimmed = {};

module.exports = {
getObjectSubset,
getPath };
{
"name": "jest-matchers",
"version": "19.0.0",
"version": "19.1.0-alpha.eed82034",
"repository": {

@@ -11,7 +11,7 @@ "type": "git",

"dependencies": {
"jest-diff": "^19.0.0",
"jest-matcher-utils": "^19.0.0",
"jest-message-util": "^19.0.0",
"jest-regex-util": "^19.0.0"
"jest-diff": "^19.1.0-alpha.eed82034",
"jest-matcher-utils": "^19.1.0-alpha.eed82034",
"jest-message-util": "^19.1.0-alpha.eed82034",
"jest-regex-util": "^19.1.0-alpha.eed82034"
}
}
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