Socket
Socket
Sign inDemoInstall

@vitest/expect

Package Overview
Dependencies
Maintainers
4
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/expect - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

7

dist/index.d.ts

@@ -240,2 +240,7 @@ import * as _vitest_utils from '@vitest/utils';

declare function pluralize(word: string, count: number): string;
declare function getObjectKeys(object: object): Array<string | symbol>;
declare function getObjectSubset(object: any, subset: any, customTesters?: Array<Tester>): {
subset: any;
stripped: number;
};

@@ -254,2 +259,2 @@ declare const MATCHERS_OBJECT: unique symbol;

export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, type Assertion, AsymmetricMatcher, type AsymmetricMatcherInterface, type AsymmetricMatchersContaining, type AsyncExpectationResult, type ChaiPlugin, type ExpectStatic, type ExpectationResult, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, type JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, type MatcherHintOptions, type MatcherState, type MatchersObject, ObjectContaining, type RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, type TesterContext, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, type Assertion, AsymmetricMatcher, type AsymmetricMatcherInterface, type AsymmetricMatchersContaining, type AsyncExpectationResult, type ChaiPlugin, type ExpectStatic, type ExpectationResult, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, type JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, type MatcherHintOptions, type MatcherState, type MatchersObject, ObjectContaining, type RawMatcherFn, StringContaining, StringMatching, type SyncExpectationResult, type Tester, type TesterContext, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };

@@ -449,2 +449,53 @@ import { getType, getColors, stringify, isObject, assertTypes } from '@vitest/utils';

}
function getObjectKeys(object) {
return [
...Object.keys(object),
...Object.getOwnPropertySymbols(object).filter(
(s) => {
var _a;
return (_a = Object.getOwnPropertyDescriptor(object, s)) == null ? void 0 : _a.enumerable;
}
)
];
}
function getObjectSubset(object, subset, customTesters = []) {
let stripped = 0;
const getObjectSubsetWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
if (Array.isArray(object2)) {
if (Array.isArray(subset2) && subset2.length === object2.length) {
return subset2.map(
(sub, i) => getObjectSubsetWithContext(seenReferences)(object2[i], sub)
);
}
} else if (object2 instanceof Date) {
return object2;
} else if (isObject(object2) && isObject(subset2)) {
if (equals(object2, subset2, [
...customTesters,
iterableEquality,
subsetEquality
])) {
return subset2;
}
const trimmed = {};
seenReferences.set(object2, trimmed);
for (const key of getObjectKeys(object2)) {
if (hasPropertyInObject(subset2, key)) {
trimmed[key] = seenReferences.has(object2[key]) ? seenReferences.get(object2[key]) : getObjectSubsetWithContext(seenReferences)(object2[key], subset2[key]);
} else {
if (!seenReferences.has(object2[key])) {
stripped += 1;
if (isObject(object2[key]))
stripped += getObjectKeys(object2[key]).length;
getObjectSubsetWithContext(seenReferences)(object2[key], subset2[key]);
}
}
}
if (getObjectKeys(trimmed).length > 0)
return trimmed;
}
return object2;
};
return { subset: getObjectSubsetWithContext()(object, subset), stripped };
}

@@ -880,12 +931,25 @@ class AsymmetricMatcher {

const actual = this._obj;
return this.assert(
equals(actual, expected, [...customTesters, iterableEquality, subsetEquality]),
"expected #{this} to match object #{exp}",
"expected #{this} to not match object #{exp}",
expected,
actual
const pass = equals(actual, expected, [...customTesters, iterableEquality, subsetEquality]);
const isNot = utils.flag(this, "negate");
const { subset: actualSubset, stripped } = getObjectSubset(actual, expected);
const msg = utils.getMessage(
this,
[
pass,
"expected #{this} to match object #{exp}",
"expected #{this} to not match object #{exp}",
expected,
actualSubset
]
);
if (pass && isNot || !pass && !isNot) {
const message = stripped === 0 ? msg : `${msg}
(${stripped} matching ${stripped === 1 ? "property" : "properties"} omitted from actual)`;
throw new AssertionError(message, { showDiff: true, expected, actual: actualSubset });
}
});
def("toMatch", function(expected) {
const actual = this._obj;
if (typeof actual !== "string")
throw new TypeError(`.toMatch() expects to receive a string, but got ${typeof actual}`);
return this.assert(

@@ -1232,8 +1296,11 @@ typeof expected === "string" ? actual.includes(expected) : actual.match(expected),

const nthCall = spy.mock.calls[times - 1];
const callCount = spy.mock.calls.length;
const isCalled = times <= callCount;
this.assert(
equals(nthCall, args, [...customTesters, iterableEquality]),
`expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`,
`expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}${isCalled ? `` : `, but called only ${callCount} times`}`,
`expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`,
args,
nthCall
nthCall,
isCalled
);

@@ -1570,2 +1637,2 @@ });

export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };

8

package.json
{
"name": "@vitest/expect",
"type": "module",
"version": "1.4.0",
"version": "1.5.0",
"description": "Jest's expect matchers as a Chai plugin",

@@ -34,4 +34,4 @@ "license": "MIT",

"chai": "^4.3.10",
"@vitest/spy": "1.4.0",
"@vitest/utils": "1.4.0"
"@vitest/utils": "1.5.0",
"@vitest/spy": "1.5.0"
},

@@ -42,3 +42,3 @@ "devDependencies": {

"rollup-plugin-copy": "^3.5.0",
"@vitest/runner": "1.4.0"
"@vitest/runner": "1.5.0"
},

@@ -45,0 +45,0 @@ "scripts": {

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