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
4
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 17.0.2 to 17.0.3

88

build/matchers.js

@@ -36,2 +36,10 @@ /**

const IteratorSymbol = Symbol.iterator;

@@ -301,10 +309,22 @@ const equals = global.jasmine.matchersUtil.equals;

const collectionType = getType(collection);
if (!Array.isArray(collection) && typeof collection !== 'string') {
throw new Error(
`.toContain() only works with arrays and strings.\n` +
printWithType('Received', collection, printReceived));
let converted = null;
if (Array.isArray(collection) || typeof collection === 'string') {
// strings have `indexOf` so we don't need to convert
// arrays have `indexOf` and we don't want to make a copy
converted = collection;
} else {
try {
converted = Array.from(collection);
} catch (e) {
throw new Error(
matcherHint('[.not].toContainEqual', 'collection', 'value') + '\n\n' +
`Expected ${ RECEIVED_COLOR('collection') } to be an array-like structure.\n` +
printWithType('Received', collection, printReceived));
}
}
const pass = collection.indexOf(value) != -1;
// At this point, we're either a string or an Array,
// which was converted from an array-like structure.
const pass = converted.indexOf(value) != -1;
const message = pass ?

@@ -327,11 +347,19 @@ () => matcherHint('.not.toContain', collectionType, 'value') + '\n\n' +

const collectionType = getType(collection);
if (!Array.isArray(collection)) {
throw new Error(
`.toContainEqual() only works with arrays.\n` +
printWithType('Received', collection, printReceived));
let converted = null;
if (Array.isArray(collection)) {
converted = collection;
} else {
try {
converted = Array.from(collection);
} catch (e) {
throw new Error(
matcherHint('[.not].toContainEqual', 'collection', 'value') + '\n\n' +
`Expected ${ RECEIVED_COLOR('collection') } to be an array-like structure.\n` +
printWithType('Received', collection, printReceived));
}
}
const pass =
collection.findIndex(item => equals(item, value, [iterableEquality])) !== -1;
converted.findIndex(item => equals(item, value, [iterableEquality])) !== -1;
const message = pass ?

@@ -376,2 +404,40 @@ () => matcherHint('.not.toContainEqual', collectionType, 'value') + '\n\n' +

toHaveLength(received, length) {
if (
typeof received !== 'string' && (
!received || typeof received.length !== 'number'))
{
throw new Error(
matcherHint('[.not].toHaveLength', 'received', 'length') + '\n\n' +
`Expected value to have a 'length' prorerty that is a number. ` +
`Received:\n` +
` ${ printReceived(received) }\n` + (
received ?
`received.length:\n ${ printReceived(received.length) }` :
''));
}
const pass = received.length === length;
const message = pass ?
() => matcherHint('.not.toHaveLength', 'received', 'length') + '\n\n' +
`Expected value to not have length:\n` +
` ${ printExpected(length) }\n` +
`Received:\n` +
` ${ printReceived(received) }\n` +
`received.length:\n` +
` ${ printReceived(received.length) }` :
() => matcherHint('.toHaveLength', 'received', 'length') + '\n\n' +
`Expected value to have length:\n` +
` ${ printExpected(length) }\n` +
`Received:\n` +
` ${ printReceived(received) }\n` +
`received.length:\n` +
` ${ printReceived(received.length) }`;
return { message, pass };
},
toMatch(received, expected) {

@@ -378,0 +444,0 @@ if (typeof received !== 'string') {

6

package.json
{
"name": "jest-matchers",
"version": "17.0.2",
"version": "17.0.3",
"repository": {

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

"dependencies": {
"jest-diff": "^17.0.2",
"jest-matcher-utils": "^17.0.1",
"jest-diff": "^17.0.3",
"jest-matcher-utils": "^17.0.3",
"jest-util": "^17.0.2"

@@ -15,0 +15,0 @@ },

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