@vitest/expect 0.30.1 → 0.31.1
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 +86 -5
- package/dist/index.js +3 -3
- package/package.json +8 -3
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { use } from 'chai';
|
2
|
-
import { stringify } from '@vitest/utils';
|
2
|
+
import { stringify, Constructable } from '@vitest/utils';
|
3
3
|
export { setupColors } from '@vitest/utils';
|
4
4
|
|
5
5
|
type Formatter = (input: string | number | null | undefined) => string;
|
@@ -104,6 +104,87 @@ interface RawMatcherFn<T extends MatcherState = MatcherState> {
|
|
104
104
|
(this: T, received: any, expected: any, options?: any): ExpectationResult;
|
105
105
|
}
|
106
106
|
type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
|
107
|
+
interface ExpectStatic extends Chai.ExpectStatic, AsymmetricMatchersContaining {
|
108
|
+
<T>(actual: T, message?: string): Assertion<T>;
|
109
|
+
extend(expects: MatchersObject): void;
|
110
|
+
assertions(expected: number): void;
|
111
|
+
hasAssertions(): void;
|
112
|
+
anything(): any;
|
113
|
+
any(constructor: unknown): any;
|
114
|
+
getState(): MatcherState;
|
115
|
+
setState(state: Partial<MatcherState>): void;
|
116
|
+
not: AsymmetricMatchersContaining;
|
117
|
+
}
|
118
|
+
interface AsymmetricMatchersContaining {
|
119
|
+
stringContaining(expected: string): any;
|
120
|
+
objectContaining<T = any>(expected: T): any;
|
121
|
+
arrayContaining<T = unknown>(expected: Array<T>): any;
|
122
|
+
stringMatching(expected: string | RegExp): any;
|
123
|
+
}
|
124
|
+
interface JestAssertion<T = any> extends jest.Matchers<void, T> {
|
125
|
+
toEqual<E>(expected: E): void;
|
126
|
+
toStrictEqual<E>(expected: E): void;
|
127
|
+
toBe<E>(expected: E): void;
|
128
|
+
toMatch(expected: string | RegExp): void;
|
129
|
+
toMatchObject<E extends {} | any[]>(expected: E): void;
|
130
|
+
toContain<E>(item: E): void;
|
131
|
+
toContainEqual<E>(item: E): void;
|
132
|
+
toBeTruthy(): void;
|
133
|
+
toBeFalsy(): void;
|
134
|
+
toBeGreaterThan(num: number | bigint): void;
|
135
|
+
toBeGreaterThanOrEqual(num: number | bigint): void;
|
136
|
+
toBeLessThan(num: number | bigint): void;
|
137
|
+
toBeLessThanOrEqual(num: number | bigint): void;
|
138
|
+
toBeNaN(): void;
|
139
|
+
toBeUndefined(): void;
|
140
|
+
toBeNull(): void;
|
141
|
+
toBeDefined(): void;
|
142
|
+
toBeInstanceOf<E>(expected: E): void;
|
143
|
+
toBeCalledTimes(times: number): void;
|
144
|
+
toHaveLength(length: number): void;
|
145
|
+
toHaveProperty<E>(property: string | (string | number)[], value?: E): void;
|
146
|
+
toBeCloseTo(number: number, numDigits?: number): void;
|
147
|
+
toHaveBeenCalledTimes(times: number): void;
|
148
|
+
toHaveBeenCalled(): void;
|
149
|
+
toBeCalled(): void;
|
150
|
+
toHaveBeenCalledWith<E extends any[]>(...args: E): void;
|
151
|
+
toBeCalledWith<E extends any[]>(...args: E): void;
|
152
|
+
toHaveBeenNthCalledWith<E extends any[]>(n: number, ...args: E): void;
|
153
|
+
nthCalledWith<E extends any[]>(nthCall: number, ...args: E): void;
|
154
|
+
toHaveBeenLastCalledWith<E extends any[]>(...args: E): void;
|
155
|
+
lastCalledWith<E extends any[]>(...args: E): void;
|
156
|
+
toThrow(expected?: string | Constructable | RegExp | Error): void;
|
157
|
+
toThrowError(expected?: string | Constructable | RegExp | Error): void;
|
158
|
+
toReturn(): void;
|
159
|
+
toHaveReturned(): void;
|
160
|
+
toReturnTimes(times: number): void;
|
161
|
+
toHaveReturnedTimes(times: number): void;
|
162
|
+
toReturnWith<E>(value: E): void;
|
163
|
+
toHaveReturnedWith<E>(value: E): void;
|
164
|
+
toHaveLastReturnedWith<E>(value: E): void;
|
165
|
+
lastReturnedWith<E>(value: E): void;
|
166
|
+
toHaveNthReturnedWith<E>(nthCall: number, value: E): void;
|
167
|
+
nthReturnedWith<E>(nthCall: number, value: E): void;
|
168
|
+
}
|
169
|
+
type VitestAssertion<A, T> = {
|
170
|
+
[K in keyof A]: A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T>;
|
171
|
+
} & ((type: string, message?: string) => Assertion);
|
172
|
+
type Promisify<O> = {
|
173
|
+
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? O extends R ? Promisify<O[K]> : (...args: A) => Promise<R> : O[K];
|
174
|
+
};
|
175
|
+
interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T> {
|
176
|
+
toBeTypeOf(expected: 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined'): void;
|
177
|
+
toHaveBeenCalledOnce(): void;
|
178
|
+
toSatisfy<E>(matcher: (value: E) => boolean, message?: string): void;
|
179
|
+
resolves: Promisify<Assertion<T>>;
|
180
|
+
rejects: Promisify<Assertion<T>>;
|
181
|
+
}
|
182
|
+
declare global {
|
183
|
+
namespace jest {
|
184
|
+
interface Matchers<R, T = {}> {
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
107
188
|
|
108
189
|
interface AsymmetricMatcherInterface {
|
109
190
|
asymmetricMatch(other: unknown): boolean;
|
@@ -116,7 +197,7 @@ declare abstract class AsymmetricMatcher<T, State extends MatcherState = Matcher
|
|
116
197
|
protected inverse: boolean;
|
117
198
|
$$typeof: symbol;
|
118
199
|
constructor(sample: T, inverse?: boolean);
|
119
|
-
protected getMatcherContext(expect?:
|
200
|
+
protected getMatcherContext(expect?: Chai.ExpectStatic): State;
|
120
201
|
abstract asymmetricMatch(other: unknown): boolean;
|
121
202
|
abstract toString(): string;
|
122
203
|
getExpectedType?(): string;
|
@@ -182,11 +263,11 @@ declare const MATCHERS_OBJECT: unique symbol;
|
|
182
263
|
declare const JEST_MATCHERS_OBJECT: unique symbol;
|
183
264
|
declare const GLOBAL_EXPECT: unique symbol;
|
184
265
|
|
185
|
-
declare function getState<State extends MatcherState = MatcherState>(expect:
|
186
|
-
declare function setState<State extends MatcherState = MatcherState>(state: Partial<State>, expect:
|
266
|
+
declare function getState<State extends MatcherState = MatcherState>(expect: ExpectStatic): State;
|
267
|
+
declare function setState<State extends MatcherState = MatcherState>(state: Partial<State>, expect: ExpectStatic): void;
|
187
268
|
|
188
269
|
declare const JestChaiExpect: ChaiPlugin;
|
189
270
|
|
190
271
|
declare const JestExtend: ChaiPlugin;
|
191
272
|
|
192
|
-
export { Any, Anything, ArrayContaining, AsymmetricMatcher, AsymmetricMatcherInterface, AsyncExpectationResult, ChaiPlugin, DiffOptions, ExpectationResult, FirstFunctionArgument, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, MatcherHintOptions, MatcherState, MatchersObject, ObjectContaining, RawMatcherFn, StringContaining, StringMatching, SyncExpectationResult, Tester, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
273
|
+
export { Any, Anything, ArrayContaining, Assertion, AsymmetricMatcher, AsymmetricMatcherInterface, AsymmetricMatchersContaining, AsyncExpectationResult, ChaiPlugin, DiffOptions, ExpectStatic, ExpectationResult, FirstFunctionArgument, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAssertion, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, MatcherHintOptions, MatcherState, MatchersObject, ObjectContaining, RawMatcherFn, StringContaining, StringMatching, SyncExpectationResult, Tester, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, setState, sparseArrayEquality, subsetEquality, typeEquality };
|
package/dist/index.js
CHANGED
@@ -225,7 +225,7 @@ function isA(typeName, value) {
|
|
225
225
|
return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
|
226
226
|
}
|
227
227
|
function isDomNode(obj) {
|
228
|
-
return obj !== null && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string" && typeof obj.isEqualNode === "function";
|
228
|
+
return obj !== null && typeof obj === "object" && "nodeType" in obj && typeof obj.nodeType === "number" && "nodeName" in obj && typeof obj.nodeName === "string" && "isEqualNode" in obj && typeof obj.isEqualNode === "function";
|
229
229
|
}
|
230
230
|
function fnNameFor(func) {
|
231
231
|
if (func.name)
|
@@ -952,7 +952,7 @@ ${spy.mock.calls.map((callArg, i) => {
|
|
952
952
|
|
953
953
|
`);
|
954
954
|
if (actualCall)
|
955
|
-
methodCall += diff(
|
955
|
+
methodCall += diff(actualCall, callArg, { showLegend: false });
|
956
956
|
else
|
957
957
|
methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
|
958
958
|
methodCall += "\n";
|
@@ -973,7 +973,7 @@ ${spy.mock.results.map((callReturn, i) => {
|
|
973
973
|
|
974
974
|
`);
|
975
975
|
if (actualReturn)
|
976
|
-
methodCall += diff(callReturn.value,
|
976
|
+
methodCall += diff(actualReturn, callReturn.value, { showLegend: false });
|
977
977
|
else
|
978
978
|
methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
|
979
979
|
methodCall += "\n";
|
package/package.json
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.31.1",
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
6
6
|
"license": "MIT",
|
7
|
+
"funding": "https://opencollective.com/vitest",
|
8
|
+
"homepage": "https://github.com/vitest-dev/vitest/tree/main/packages/expect#readme",
|
7
9
|
"repository": {
|
8
10
|
"type": "git",
|
9
11
|
"url": "git+https://github.com/vitest-dev/vitest.git",
|
10
12
|
"directory": "packages/expect"
|
11
13
|
},
|
14
|
+
"bugs": {
|
15
|
+
"url": "https://github.com/vitest-dev/vitest/issues"
|
16
|
+
},
|
12
17
|
"sideEffects": false,
|
13
18
|
"exports": {
|
14
19
|
".": {
|
@@ -25,8 +30,8 @@
|
|
25
30
|
],
|
26
31
|
"dependencies": {
|
27
32
|
"chai": "^4.3.7",
|
28
|
-
"@vitest/
|
29
|
-
"@vitest/
|
33
|
+
"@vitest/utils": "0.31.1",
|
34
|
+
"@vitest/spy": "0.31.1"
|
30
35
|
},
|
31
36
|
"devDependencies": {
|
32
37
|
"picocolors": "^1.0.0"
|