@vitest/expect 4.1.1 → 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 +3 -3
- package/dist/index.js +18 -9
- package/package.json +5 -5
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,13 +156,13 @@ 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;
|
|
164
162
|
message: () => string;
|
|
165
163
|
actual?: any;
|
|
166
164
|
expected?: any;
|
|
165
|
+
meta?: object;
|
|
167
166
|
}
|
|
168
167
|
type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
169
168
|
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
@@ -916,8 +915,9 @@ declare function isStandardSchema(obj: any): obj is StandardSchemaV1;
|
|
|
916
915
|
declare function getState<State extends MatcherState = MatcherState>(expect: ExpectStatic): State;
|
|
917
916
|
declare function setState<State extends MatcherState = MatcherState>(state: Partial<State>, expect: ExpectStatic): void;
|
|
918
917
|
|
|
919
|
-
declare function createAssertionMessage(util: Chai.ChaiUtils, assertion: Assertion, hasArgs: boolean): string;
|
|
918
|
+
declare function createAssertionMessage(util: Chai.ChaiUtils, assertion: Chai.Assertion, hasArgs: boolean): string;
|
|
920
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` */
|
|
921
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>;
|
|
922
922
|
|
|
923
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,34 +1857,41 @@ 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;
|
|
1864
|
+
this.__vitest_error_context__ = __vitest_error_context__;
|
|
1862
1865
|
}
|
|
1863
1866
|
}
|
|
1864
1867
|
function JestExtendPlugin(c, expect, matchers) {
|
|
1865
1868
|
return (_, utils) => {
|
|
1866
1869
|
Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
|
|
1867
|
-
function
|
|
1870
|
+
function __VITEST_EXTEND_ASSERTION__(...args) {
|
|
1868
1871
|
const { state, isNot, obj, customMessage } = getMatcherState(this, expect);
|
|
1869
1872
|
const result = expectAssertion.call(state, obj, ...args);
|
|
1870
1873
|
if (result && typeof result === "object" && typeof result.then === "function") {
|
|
1871
1874
|
const thenable = result;
|
|
1872
|
-
return thenable.then(({ pass, message, actual, expected }) => {
|
|
1875
|
+
return thenable.then(({ pass, message, actual, expected, meta }) => {
|
|
1873
1876
|
if (pass && isNot || !pass && !isNot) {
|
|
1874
1877
|
const errorMessage = customMessage != null ? customMessage : message();
|
|
1875
|
-
throw new JestExtendError(errorMessage, actual, expected
|
|
1878
|
+
throw new JestExtendError(errorMessage, actual, expected, {
|
|
1879
|
+
assertionName: expectAssertionName,
|
|
1880
|
+
meta
|
|
1881
|
+
});
|
|
1876
1882
|
}
|
|
1877
1883
|
});
|
|
1878
1884
|
}
|
|
1879
|
-
const { pass, message, actual, expected } = result;
|
|
1885
|
+
const { pass, message, actual, expected, meta } = result;
|
|
1880
1886
|
if (pass && isNot || !pass && !isNot) {
|
|
1881
1887
|
const errorMessage = customMessage != null ? customMessage : message();
|
|
1882
|
-
throw new JestExtendError(errorMessage, actual, expected
|
|
1888
|
+
throw new JestExtendError(errorMessage, actual, expected, {
|
|
1889
|
+
assertionName: expectAssertionName,
|
|
1890
|
+
meta
|
|
1891
|
+
});
|
|
1883
1892
|
}
|
|
1884
1893
|
}
|
|
1885
|
-
const softWrapper = wrapAssertion(utils, expectAssertionName,
|
|
1894
|
+
const softWrapper = wrapAssertion(utils, expectAssertionName, __VITEST_EXTEND_ASSERTION__);
|
|
1886
1895
|
utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, softWrapper);
|
|
1887
1896
|
utils.addMethod(c.Assertion.prototype, expectAssertionName, softWrapper);
|
|
1888
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",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"@standard-schema/spec": "^1.1.0",
|
|
39
39
|
"@types/chai": "^5.2.2",
|
|
40
40
|
"chai": "^6.2.2",
|
|
41
|
-
"tinyrainbow": "^3.0
|
|
42
|
-
"@vitest/spy": "4.1.
|
|
43
|
-
"@vitest/utils": "4.1.
|
|
41
|
+
"tinyrainbow": "^3.1.0",
|
|
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",
|