@vitest/expect 4.1.2 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -3
- package/dist/index.js +8 -6
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Test } from '@vitest/runner';
|
|
2
1
|
import { MockInstance } from '@vitest/spy';
|
|
3
2
|
import { Formatter } from 'tinyrainbow';
|
|
4
3
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
@@ -157,7 +156,6 @@ interface MatcherState {
|
|
|
157
156
|
};
|
|
158
157
|
soft?: boolean;
|
|
159
158
|
poll?: boolean;
|
|
160
|
-
task?: Readonly<Test>;
|
|
161
159
|
}
|
|
162
160
|
interface SyncExpectationResult {
|
|
163
161
|
pass: boolean;
|
|
@@ -917,8 +915,9 @@ declare function isStandardSchema(obj: any): obj is StandardSchemaV1;
|
|
|
917
915
|
declare function getState<State extends MatcherState = MatcherState>(expect: ExpectStatic): State;
|
|
918
916
|
declare function setState<State extends MatcherState = MatcherState>(state: Partial<State>, expect: ExpectStatic): void;
|
|
919
917
|
|
|
920
|
-
declare function createAssertionMessage(util: Chai.ChaiUtils, assertion: Assertion, hasArgs: boolean): string;
|
|
918
|
+
declare function createAssertionMessage(util: Chai.ChaiUtils, assertion: Chai.Assertion, hasArgs: boolean): string;
|
|
921
919
|
declare function recordAsyncExpect(_test: any, promise: Promise<any>, assertion: string, error: Error, isSoft?: boolean): Promise<any>;
|
|
920
|
+
/** wrap assertion function to support `expect.soft` and provide assertion name as `_name` */
|
|
922
921
|
declare function wrapAssertion(utils: Chai.ChaiUtils, name: string, fn: (this: Chai.AssertionStatic & Assertion, ...args: any[]) => void | PromiseLike<void>): (this: Chai.AssertionStatic & Assertion, ...args: any[]) => void | PromiseLike<void>;
|
|
923
922
|
|
|
924
923
|
export { ASYMMETRIC_MATCHERS_OBJECT, Any, Anything, ArrayContaining, AsymmetricMatcher, ChaiStyleAssertions, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, ObjectContaining, SchemaMatching, StringContaining, StringMatching, addCustomEqualityTesters, arrayBufferEquality, createAssertionMessage, customMatchers, equals, fnNameFor, generateToBeMessage, getObjectKeys, getObjectSubset, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isError, isImmutableUnorderedKeyed, isImmutableUnorderedSet, isStandardSchema, iterableEquality, pluralize, recordAsyncExpect, setState, sparseArrayEquality, subsetEquality, typeEquality, wrapAssertion };
|
package/dist/index.js
CHANGED
|
@@ -1142,6 +1142,7 @@ function handleTestError(test, err) {
|
|
|
1142
1142
|
test.result.errors ||= [];
|
|
1143
1143
|
test.result.errors.push(processError(err));
|
|
1144
1144
|
}
|
|
1145
|
+
/** wrap assertion function to support `expect.soft` and provide assertion name as `_name` */
|
|
1145
1146
|
function wrapAssertion(utils, name, fn) {
|
|
1146
1147
|
return function(...args) {
|
|
1147
1148
|
// private
|
|
@@ -1836,7 +1837,6 @@ function getMatcherState(assertion, expect) {
|
|
|
1836
1837
|
}
|
|
1837
1838
|
const matcherState = {
|
|
1838
1839
|
...getState(expect),
|
|
1839
|
-
task,
|
|
1840
1840
|
currentTestName,
|
|
1841
1841
|
customTesters: getCustomEqualityTesters(),
|
|
1842
1842
|
isNot,
|
|
@@ -1845,8 +1845,10 @@ function getMatcherState(assertion, expect) {
|
|
|
1845
1845
|
equals,
|
|
1846
1846
|
suppressedErrors: [],
|
|
1847
1847
|
soft: util.flag(assertion, "soft"),
|
|
1848
|
-
poll: util.flag(assertion, "poll")
|
|
1848
|
+
poll: util.flag(assertion, "poll"),
|
|
1849
|
+
__vitest_assertion__: assertion
|
|
1849
1850
|
};
|
|
1851
|
+
Object.assign(matcherState, { task });
|
|
1850
1852
|
return {
|
|
1851
1853
|
state: matcherState,
|
|
1852
1854
|
isNot,
|
|
@@ -1855,17 +1857,17 @@ function getMatcherState(assertion, expect) {
|
|
|
1855
1857
|
};
|
|
1856
1858
|
}
|
|
1857
1859
|
class JestExtendError extends Error {
|
|
1858
|
-
constructor(message, actual, expected,
|
|
1860
|
+
constructor(message, actual, expected, __vitest_error_context__) {
|
|
1859
1861
|
super(message);
|
|
1860
1862
|
this.actual = actual;
|
|
1861
1863
|
this.expected = expected;
|
|
1862
|
-
this.
|
|
1864
|
+
this.__vitest_error_context__ = __vitest_error_context__;
|
|
1863
1865
|
}
|
|
1864
1866
|
}
|
|
1865
1867
|
function JestExtendPlugin(c, expect, matchers) {
|
|
1866
1868
|
return (_, utils) => {
|
|
1867
1869
|
Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
|
|
1868
|
-
function
|
|
1870
|
+
function __VITEST_EXTEND_ASSERTION__(...args) {
|
|
1869
1871
|
const { state, isNot, obj, customMessage } = getMatcherState(this, expect);
|
|
1870
1872
|
const result = expectAssertion.call(state, obj, ...args);
|
|
1871
1873
|
if (result && typeof result === "object" && typeof result.then === "function") {
|
|
@@ -1889,7 +1891,7 @@ function JestExtendPlugin(c, expect, matchers) {
|
|
|
1889
1891
|
});
|
|
1890
1892
|
}
|
|
1891
1893
|
}
|
|
1892
|
-
const softWrapper = wrapAssertion(utils, expectAssertionName,
|
|
1894
|
+
const softWrapper = wrapAssertion(utils, expectAssertionName, __VITEST_EXTEND_ASSERTION__);
|
|
1893
1895
|
utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, softWrapper);
|
|
1894
1896
|
utils.addMethod(c.Assertion.prototype, expectAssertionName, softWrapper);
|
|
1895
1897
|
class CustomMatcher extends AsymmetricMatcher {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/expect",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.3",
|
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"@types/chai": "^5.2.2",
|
|
40
40
|
"chai": "^6.2.2",
|
|
41
41
|
"tinyrainbow": "^3.1.0",
|
|
42
|
-
"@vitest/spy": "4.1.
|
|
43
|
-
"@vitest/utils": "4.1.
|
|
42
|
+
"@vitest/spy": "4.1.3",
|
|
43
|
+
"@vitest/utils": "4.1.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@vitest/runner": "4.1.
|
|
46
|
+
"@vitest/runner": "4.1.3"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "premove dist && rollup -c",
|