@vitest/expect 2.0.0-beta.1 → 2.0.0-beta.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 +5 -8
- package/dist/index.js +16 -6
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
@@ -65,6 +65,7 @@ interface MatcherState {
|
|
65
65
|
subsetEquality: Tester;
|
66
66
|
};
|
67
67
|
soft?: boolean;
|
68
|
+
poll?: boolean;
|
68
69
|
}
|
69
70
|
interface SyncExpectationResult {
|
70
71
|
pass: boolean;
|
@@ -80,12 +81,7 @@ interface RawMatcherFn<T extends MatcherState = MatcherState> {
|
|
80
81
|
type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
|
81
82
|
interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
|
82
83
|
<T>(actual: T, message?: string): Assertion<T>;
|
83
|
-
unreachable: (message?: string) => never;
|
84
|
-
soft: <T>(actual: T, message?: string) => Assertion<T>;
|
85
84
|
extend: (expects: MatchersObject) => void;
|
86
|
-
addEqualityTesters: (testers: Array<Tester>) => void;
|
87
|
-
assertions: (expected: number) => void;
|
88
|
-
hasAssertions: () => void;
|
89
85
|
anything: () => any;
|
90
86
|
any: (constructor: unknown) => any;
|
91
87
|
getState: () => MatcherState;
|
@@ -150,12 +146,13 @@ type VitestAssertion<A, T> = {
|
|
150
146
|
type Promisify<O> = {
|
151
147
|
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? O extends R ? Promisify<O[K]> : (...args: A) => Promise<R> : O[K];
|
152
148
|
};
|
149
|
+
type PromisifyAssertion<T> = Promisify<Assertion<T>>;
|
153
150
|
interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T> {
|
154
151
|
toBeTypeOf: (expected: 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined') => void;
|
155
152
|
toHaveBeenCalledOnce: () => void;
|
156
153
|
toSatisfy: <E>(matcher: (value: E) => boolean, message?: string) => void;
|
157
|
-
resolves:
|
158
|
-
rejects:
|
154
|
+
resolves: PromisifyAssertion<T>;
|
155
|
+
rejects: PromisifyAssertion<T>;
|
159
156
|
}
|
160
157
|
declare global {
|
161
158
|
namespace jest {
|
@@ -255,4 +252,4 @@ declare const JestChaiExpect: ChaiPlugin;
|
|
255
252
|
|
256
253
|
declare const JestExtend: ChaiPlugin;
|
257
254
|
|
258
|
-
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 };
|
255
|
+
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 PromisifyAssertion, 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 };
|
package/dist/index.js
CHANGED
@@ -254,7 +254,7 @@ function isDomNode(obj) {
|
|
254
254
|
function fnNameFor(func) {
|
255
255
|
if (func.name)
|
256
256
|
return func.name;
|
257
|
-
const matches = functionToString.call(func).match(/^(?:async)?\s*function\s
|
257
|
+
const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*(?:\*\s*)?([\w$]+)\s*\(/);
|
258
258
|
return matches ? matches[1] : "<anonymous>";
|
259
259
|
}
|
260
260
|
function getPrototype(obj) {
|
@@ -661,7 +661,7 @@ class Any extends AsymmetricMatcher {
|
|
661
661
|
if (func.name)
|
662
662
|
return func.name;
|
663
663
|
const functionToString = Function.prototype.toString;
|
664
|
-
const matches = functionToString.call(func).match(/^(?:async)?\s*function\s
|
664
|
+
const matches = functionToString.call(func).match(/^(?:async)?\s*function\s*(?:\*\s*)?([\w$]+)\s*\(/);
|
665
665
|
return matches ? matches[1] : "<anonymous>";
|
666
666
|
}
|
667
667
|
asymmetricMatch(other) {
|
@@ -817,10 +817,9 @@ function recordAsyncExpect(test, promise) {
|
|
817
817
|
function wrapSoft(utils, fn) {
|
818
818
|
return function(...args) {
|
819
819
|
var _a;
|
820
|
-
|
821
|
-
const state = (test == null ? void 0 : test.context._local) ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
822
|
-
if (!state.soft)
|
820
|
+
if (!utils.flag(this, "soft"))
|
823
821
|
return fn.apply(this, args);
|
822
|
+
const test = utils.flag(this, "vitest-test");
|
824
823
|
if (!test)
|
825
824
|
throw new Error("expect.soft() can only be used inside a test");
|
826
825
|
try {
|
@@ -1484,12 +1483,19 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1484
1483
|
def("toSatisfy", function(matcher, message) {
|
1485
1484
|
return this.be.satisfy(matcher, message);
|
1486
1485
|
});
|
1486
|
+
def("withContext", function(context) {
|
1487
|
+
for (const key in context)
|
1488
|
+
utils.flag(this, key, context[key]);
|
1489
|
+
return this;
|
1490
|
+
});
|
1487
1491
|
utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() {
|
1488
1492
|
const error = new Error("resolves");
|
1489
1493
|
utils.flag(this, "promise", "resolves");
|
1490
1494
|
utils.flag(this, "error", error);
|
1491
1495
|
const test = utils.flag(this, "vitest-test");
|
1492
1496
|
const obj = utils.flag(this, "object");
|
1497
|
+
if (utils.flag(this, "poll"))
|
1498
|
+
throw new SyntaxError(`expect.poll() is not supported in combination with .resolves`);
|
1493
1499
|
if (typeof (obj == null ? void 0 : obj.then) !== "function")
|
1494
1500
|
throw new TypeError(`You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`);
|
1495
1501
|
const proxy = new Proxy(this, {
|
@@ -1526,6 +1532,8 @@ Number of calls: ${c().bold(spy.mock.calls.length)}
|
|
1526
1532
|
const test = utils.flag(this, "vitest-test");
|
1527
1533
|
const obj = utils.flag(this, "object");
|
1528
1534
|
const wrapper = typeof obj === "function" ? obj() : obj;
|
1535
|
+
if (utils.flag(this, "poll"))
|
1536
|
+
throw new SyntaxError(`expect.poll() is not supported in combination with .rejects`);
|
1529
1537
|
if (typeof (wrapper == null ? void 0 : wrapper.then) !== "function")
|
1530
1538
|
throw new TypeError(`You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`);
|
1531
1539
|
const proxy = new Proxy(this, {
|
@@ -1575,7 +1583,9 @@ function getMatcherState(assertion, expect) {
|
|
1575
1583
|
promise,
|
1576
1584
|
equals,
|
1577
1585
|
// needed for built-in jest-snapshots, but we don't use it
|
1578
|
-
suppressedErrors: []
|
1586
|
+
suppressedErrors: [],
|
1587
|
+
soft: util.flag(assertion, "soft"),
|
1588
|
+
poll: util.flag(assertion, "poll")
|
1579
1589
|
};
|
1580
1590
|
return {
|
1581
1591
|
state: matcherState,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.0.0-beta.
|
4
|
+
"version": "2.0.0-beta.3",
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -31,14 +31,14 @@
|
|
31
31
|
],
|
32
32
|
"dependencies": {
|
33
33
|
"chai": "^5.1.1",
|
34
|
-
"@vitest/spy": "2.0.0-beta.
|
35
|
-
"@vitest/utils": "2.0.0-beta.
|
34
|
+
"@vitest/spy": "2.0.0-beta.3",
|
35
|
+
"@vitest/utils": "2.0.0-beta.3"
|
36
36
|
},
|
37
37
|
"devDependencies": {
|
38
38
|
"@types/chai": "4.3.6",
|
39
39
|
"picocolors": "^1.0.0",
|
40
40
|
"rollup-plugin-copy": "^3.5.0",
|
41
|
-
"@vitest/runner": "2.0.0-beta.
|
41
|
+
"@vitest/runner": "2.0.0-beta.3"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|