Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vitest/expect

Package Overview
Dependencies
Maintainers
4
Versions
101
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 2.0.4 to 2.0.5

13

dist/index.d.ts
import * as tinyrainbow from 'tinyrainbow';
import { Formatter } from 'tinyrainbow';
import { stringify, Constructable } from '@vitest/utils';
import { diff } from '@vitest/utils/diff';
import { diff, printDiffOrStringify } from '@vitest/utils/diff';
export { DiffOptions } from '@vitest/utils/diff';
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
declare function printReceived(object: unknown): string;
declare function printExpected(value: unknown): string;
declare function getMatcherUtils(): {

@@ -13,5 +16,7 @@ EXPECTED_COLOR: tinyrainbow.Formatter;

DIM_COLOR: tinyrainbow.Formatter;
matcherHint: (matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions) => string;
printReceived: (object: unknown) => string;
printExpected: (value: unknown) => string;
diff: typeof diff;
matcherHint: typeof matcherHint;
printReceived: typeof printReceived;
printExpected: typeof printExpected;
printDiffOrStringify: typeof printDiffOrStringify;
};

@@ -18,0 +23,0 @@ declare function addCustomEqualityTesters(newTesters: Array<Tester>): void;

import { getType, stringify, isObject, assertTypes } from '@vitest/utils';
import c from 'tinyrainbow';
import { diff } from '@vitest/utils/diff';
import { diff, printDiffOrStringify } from '@vitest/utils/diff';
import { isMockFunction } from '@vitest/spy';

@@ -45,61 +45,67 @@ import { processError } from '@vitest/utils/error';

function getMatcherUtils() {
const EXPECTED_COLOR = c.green;
const RECEIVED_COLOR = c.red;
const INVERTED_COLOR = c.inverse;
const BOLD_WEIGHT = c.bold;
const DIM_COLOR = c.dim;
function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
const {
comment = "",
isDirectExpectCall = false,
// seems redundant with received === ''
isNot = false,
promise = "",
secondArgument = "",
expectedColor = EXPECTED_COLOR,
receivedColor = RECEIVED_COLOR,
secondArgumentColor = EXPECTED_COLOR
} = options;
let hint = "";
let dimString = "expect";
if (!isDirectExpectCall && received !== "") {
hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
dimString = ")";
const EXPECTED_COLOR = c.green;
const RECEIVED_COLOR = c.red;
const INVERTED_COLOR = c.inverse;
const BOLD_WEIGHT = c.bold;
const DIM_COLOR = c.dim;
function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
const {
comment = "",
isDirectExpectCall = false,
// seems redundant with received === ''
isNot = false,
promise = "",
secondArgument = "",
expectedColor = EXPECTED_COLOR,
receivedColor = RECEIVED_COLOR,
secondArgumentColor = EXPECTED_COLOR
} = options;
let hint = "";
let dimString = "expect";
if (!isDirectExpectCall && received !== "") {
hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
dimString = ")";
}
if (promise !== "") {
hint += DIM_COLOR(`${dimString}.`) + promise;
dimString = "";
}
if (isNot) {
hint += `${DIM_COLOR(`${dimString}.`)}not`;
dimString = "";
}
if (matcherName.includes(".")) {
dimString += matcherName;
} else {
hint += DIM_COLOR(`${dimString}.`) + matcherName;
dimString = "";
}
if (expected === "") {
dimString += "()";
} else {
hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
if (secondArgument) {
hint += DIM_COLOR(", ") + secondArgumentColor(secondArgument);
}
if (promise !== "") {
hint += DIM_COLOR(`${dimString}.`) + promise;
dimString = "";
}
if (isNot) {
hint += `${DIM_COLOR(`${dimString}.`)}not`;
dimString = "";
}
if (matcherName.includes(".")) {
dimString += matcherName;
} else {
hint += DIM_COLOR(`${dimString}.`) + matcherName;
dimString = "";
}
if (expected === "") {
dimString += "()";
} else {
hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
if (secondArgument) {
hint += DIM_COLOR(", ") + secondArgumentColor(secondArgument);
}
dimString = ")";
}
if (comment !== "") {
dimString += ` // ${comment}`;
}
if (dimString !== "") {
hint += DIM_COLOR(dimString);
}
return hint;
dimString = ")";
}
const SPACE_SYMBOL = "\xB7";
const replaceTrailingSpaces = (text) => text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
const printReceived = (object) => RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
const printExpected = (value) => EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
if (comment !== "") {
dimString += ` // ${comment}`;
}
if (dimString !== "") {
hint += DIM_COLOR(dimString);
}
return hint;
}
const SPACE_SYMBOL = "\xB7";
function replaceTrailingSpaces(text) {
return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
}
function printReceived(object) {
return RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
}
function printExpected(value) {
return EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
}
function getMatcherUtils() {
return {

@@ -111,5 +117,7 @@ EXPECTED_COLOR,

DIM_COLOR,
diff,
matcherHint,
printReceived,
printExpected
printExpected,
printDiffOrStringify
};

@@ -116,0 +124,0 @@ }

{
"name": "@vitest/expect",
"type": "module",
"version": "2.0.4",
"version": "2.0.5",
"description": "Jest's expect matchers as a Chai plugin",

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

"tinyrainbow": "^1.2.0",
"@vitest/utils": "2.0.4",
"@vitest/spy": "2.0.4"
"@vitest/spy": "2.0.5",
"@vitest/utils": "2.0.5"
},

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

"rollup-plugin-copy": "^3.5.0",
"@vitest/runner": "2.0.4"
"@vitest/runner": "2.0.5"
},

@@ -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