Socket
Socket
Sign inDemoInstall

@vitest/expect

Package Overview
Dependencies
Maintainers
3
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.1.3 to 1.2.0

46

dist/index.d.ts

@@ -0,1 +1,2 @@

import * as _vitest_utils from '@vitest/utils';
import { stringify, Constructable } from '@vitest/utils';

@@ -9,27 +10,7 @@ export { setupColors } from '@vitest/utils';

declare function getMatcherUtils(): {
EXPECTED_COLOR: {
(input: unknown): string;
open: string;
close: string;
};
RECEIVED_COLOR: {
(input: unknown): string;
open: string;
close: string;
};
INVERTED_COLOR: {
(input: unknown): string;
open: string;
close: string;
};
BOLD_WEIGHT: {
(input: unknown): string;
open: string;
close: string;
};
DIM_COLOR: {
(input: unknown): string;
open: string;
close: string;
};
EXPECTED_COLOR: _vitest_utils.ColorMethod;
RECEIVED_COLOR: _vitest_utils.ColorMethod;
INVERTED_COLOR: _vitest_utils.ColorMethod;
BOLD_WEIGHT: _vitest_utils.ColorMethod;
DIM_COLOR: _vitest_utils.ColorMethod;
matcherHint: (matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions) => string;

@@ -39,2 +20,3 @@ printReceived: (object: unknown) => string;

};
declare function addCustomEqualityTesters(newTesters: Array<Tester>): void;

@@ -50,3 +32,6 @@ /**

type ChaiPlugin = Chai.ChaiPlugin;
type Tester = (a: any, b: any) => boolean | undefined;
type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
interface TesterContext {
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
}

@@ -104,2 +89,3 @@ interface MatcherHintOptions {

extend(expects: MatchersObject): void;
addEqualityTesters(testers: Array<Tester>): void;
assertions(expected: number): void;

@@ -251,7 +237,7 @@ hasAssertions(): void;

declare function isImmutableUnorderedSet(maybeSet: any): boolean;
declare function iterableEquality(a: any, b: any, aStack?: Array<any>, bStack?: Array<any>): boolean | undefined;
declare function subsetEquality(object: unknown, subset: unknown): boolean | undefined;
declare function iterableEquality(a: any, b: any, customTesters?: Array<Tester>, aStack?: Array<any>, bStack?: Array<any>): boolean | undefined;
declare function subsetEquality(object: unknown, subset: unknown, customTesters?: Array<Tester>): boolean | undefined;
declare function typeEquality(a: any, b: any): boolean | undefined;
declare function arrayBufferEquality(a: unknown, b: unknown): boolean | undefined;
declare function sparseArrayEquality(a: unknown, b: unknown): boolean | undefined;
declare function sparseArrayEquality(a: unknown, b: unknown, customTesters?: Array<Tester>): boolean | undefined;
declare function generateToBeMessage(deepEqualityName: string, expected?: string, actual?: string): string;

@@ -272,2 +258,2 @@ declare function pluralize(word: string, count: number): string;

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, 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, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };

@@ -1,2 +0,2 @@

import { getColors, stringify, isObject, assertTypes } from '@vitest/utils';
import { getType, getColors, stringify, isObject, assertTypes } from '@vitest/utils';
export { setupColors } from '@vitest/utils';

@@ -16,2 +16,3 @@ import { diff } from '@vitest/utils/diff';

const matchers = /* @__PURE__ */ Object.create(null);
const customEqualityTesters = [];
const assymetricMatchers = /* @__PURE__ */ Object.create(null);

@@ -25,3 +26,4 @@ Object.defineProperty(globalThis, MATCHERS_OBJECT, {

state: globalState.get(globalThis[GLOBAL_EXPECT]),
matchers
matchers,
customEqualityTesters
})

@@ -111,2 +113,17 @@ });

}
function addCustomEqualityTesters(newTesters) {
if (!Array.isArray(newTesters)) {
throw new TypeError(
`expect.customEqualityTesters: Must be set to an array of Testers. Was given "${getType(
newTesters
)}"`
);
}
globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters.push(
...newTesters
);
}
function getCustomEqualityTesters() {
return globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters;
}

@@ -150,4 +167,5 @@ function equals(a, b, customTesters, strictCheck) {

return asymmetricResult;
const testerContext = { equals };
for (let i = 0; i < customTesters.length; i++) {
const customTesterResult = customTesters[i](a, b);
const customTesterResult = customTesters[i].call(testerContext, a, b, customTesters);
if (customTesterResult !== void 0)

@@ -273,3 +291,3 @@ return customTesterResult;

}
function iterableEquality(a, b, aStack = [], bStack = []) {
function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b))

@@ -286,3 +304,15 @@ return void 0;

bStack.push(b);
const iterableEqualityWithStack = (a2, b2) => iterableEquality(a2, b2, [...aStack], [...bStack]);
const filteredCustomTesters = [
...customTesters.filter((t) => t !== iterableEquality),
iterableEqualityWithStack
];
function iterableEqualityWithStack(a2, b2) {
return iterableEquality(
a2,
b2,
[...filteredCustomTesters],
[...aStack],
[...bStack]
);
}
if (a.size !== void 0) {

@@ -297,3 +327,3 @@ if (a.size !== b.size) {

for (const bValue of b) {
const isEqual = equals(aValue, bValue, [iterableEqualityWithStack]);
const isEqual = equals(aValue, bValue, filteredCustomTesters);
if (isEqual === true)

@@ -314,14 +344,9 @@ has = true;

for (const aEntry of a) {
if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]), [iterableEqualityWithStack])) {
if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]), filteredCustomTesters)) {
let has = false;
for (const bEntry of b) {
const matchedKey = equals(aEntry[0], bEntry[0], [
iterableEqualityWithStack
]);
const matchedKey = equals(aEntry[0], bEntry[0], filteredCustomTesters);
let matchedValue = false;
if (matchedKey === true) {
matchedValue = equals(aEntry[1], bEntry[1], [
iterableEqualityWithStack
]);
}
if (matchedKey === true)
matchedValue = equals(aEntry[1], bEntry[1], filteredCustomTesters);
if (matchedValue === true)

@@ -344,3 +369,3 @@ has = true;

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

@@ -363,3 +388,4 @@ }

}
function subsetEquality(object, subset) {
function subsetEquality(object, subset, customTesters = []) {
const filteredCustomTesters = customTesters.filter((t) => t !== subsetEquality);
const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {

@@ -371,7 +397,7 @@ if (!isObjectWithKeys(subset2))

if (seenReferences.has(subset2[key]))
return equals(object2[key], subset2[key], [iterableEquality]);
return equals(object2[key], subset2[key], filteredCustomTesters);
seenReferences.set(subset2[key], true);
}
const result = object2 != null && hasPropertyInObject(object2, key) && equals(object2[key], subset2[key], [
iterableEquality,
...filteredCustomTesters,
subsetEqualityWithContext(seenReferences)

@@ -411,3 +437,3 @@ ]);

}
function sparseArrayEquality(a, b) {
function sparseArrayEquality(a, b, customTesters = []) {
if (!Array.isArray(a) || !Array.isArray(b))

@@ -417,3 +443,4 @@ return void 0;

const bKeys = Object.keys(b);
return equals(a, b, [iterableEquality, typeEquality], true) && equals(aKeys, bKeys);
const filteredCustomTesters = customTesters.filter((t) => t !== sparseArrayEquality);
return equals(a, b, filteredCustomTesters, true) && equals(aKeys, bKeys);
}

@@ -448,3 +475,3 @@ function generateToBeMessage(deepEqualityName, expected = "#{this}", actual = "#{exp}") {

isNot: this.inverse,
customTesters: [],
customTesters: getCustomEqualityTesters(),
utils: {

@@ -513,4 +540,5 @@ ...getMatcherUtils(),

let result = true;
const matcherContext = this.getMatcherContext();
for (const property in this.sample) {
if (!this.hasProperty(other, property) || !equals(this.sample[property], other[property])) {
if (!this.hasProperty(other, property) || !equals(this.sample[property], other[property], matcherContext.customTesters)) {
result = false;

@@ -539,4 +567,5 @@ break;

}
const matcherContext = this.getMatcherContext();
const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every(
(item) => other.some((another) => equals(item, another))
(item) => other.some((another) => equals(item, another, matcherContext.customTesters))
);

@@ -741,2 +770,3 @@ return this.inverse ? !result : result;

const c = () => getColors();
const customTesters = getCustomEqualityTesters();
function def(name, fn) {

@@ -787,3 +817,3 @@ const addMethod = (n) => {

expected,
[iterableEquality]
[...customTesters, iterableEquality]
);

@@ -804,2 +834,3 @@ return this.assert(

[
...customTesters,
iterableEquality,

@@ -829,2 +860,3 @@ typeEquality,

[
...customTesters,
iterableEquality,

@@ -843,3 +875,3 @@ typeEquality,

expected,
[iterableEquality]
[...customTesters, iterableEquality]
);

@@ -861,3 +893,3 @@ if (toEqualPass)

return this.assert(
equals(actual, expected, [iterableEquality, subsetEquality]),
equals(actual, expected, [...customTesters, iterableEquality, subsetEquality]),
"expected #{this} to match object #{exp}",

@@ -907,3 +939,3 @@ "expected #{this} to not match object #{exp}",

const index = Array.from(obj).findIndex((item) => {
return equals(item, expected);
return equals(item, expected, customTesters);
});

@@ -1034,3 +1066,3 @@ this.assert(

const { value, exists } = getValue();
const pass = exists && (args.length === 1 || equals(expected, value));
const pass = exists && (args.length === 1 || equals(expected, value, customTesters));
const valueString = args.length === 1 ? "" : ` with value ${utils.objDisplay(expected)}`;

@@ -1183,3 +1215,3 @@ return this.assert(

const spyName = spy.getMockName();
const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [...customTesters, iterableEquality]));
const isNot = utils.flag(this, "negate");

@@ -1203,3 +1235,3 @@ const msg = utils.getMessage(

this.assert(
equals(nthCall, args, [iterableEquality]),
equals(nthCall, args, [...customTesters, iterableEquality]),
`expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`,

@@ -1216,3 +1248,3 @@ `expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`,

this.assert(
equals(lastCall, args, [iterableEquality]),
equals(lastCall, args, [...customTesters, iterableEquality]),
`expected last "${spyName}" call to have been called with #{exp}`,

@@ -1453,4 +1485,3 @@ `expected last "${spyName}" call to not have been called with #{exp}`,

...getState(expect),
// TODO: implement via expect.addEqualityTesters
customTesters: [],
customTesters: getCustomEqualityTesters(),
isNot,

@@ -1545,2 +1576,2 @@ utils: jestUtils,

export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, StringContaining, StringMatching, 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, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, pluralize, setState, sparseArrayEquality, subsetEquality, typeEquality };
{
"name": "@vitest/expect",
"type": "module",
"version": "1.1.3",
"version": "1.2.0",
"description": "Jest's expect matchers as a Chai plugin",

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

"chai": "^4.3.10",
"@vitest/spy": "1.1.3",
"@vitest/utils": "1.1.3"
"@vitest/spy": "1.2.0",
"@vitest/utils": "1.2.0"
},

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

"rollup-plugin-copy": "^3.5.0",
"@vitest/runner": "1.1.3"
"@vitest/runner": "1.2.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