@vitest/expect 0.27.0
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/LICENSE +22 -0
- package/README.md +17 -0
- package/dist/index.d.ts +191 -0
- package/dist/index.js +1331 -0
- package/package.json +36 -0
package/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021-Present Anthony Fu <https://github.com/antfu>
|
4
|
+
Copyright (c) 2021-Present Matias Capeletto <https://github.com/patak-dev>
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# @vitest/expect
|
2
|
+
|
3
|
+
Jest's expect matchers as a Chai plugin.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```js
|
8
|
+
import * as chai from 'chai'
|
9
|
+
import { JestAsymmetricMatchers, JestChaiExpect, JestExtend } from '@vitest/expect'
|
10
|
+
|
11
|
+
// allows using expect.extend instead of chai.use to extend plugins
|
12
|
+
chai.use(JestExtend)
|
13
|
+
// adds all jest matchers to expect
|
14
|
+
chai.use(JestChaiExpect)
|
15
|
+
// adds asymmetric matchers like stringContaining, objectContaining
|
16
|
+
chai.use(JestAsymmetricMatchers)
|
17
|
+
```
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
import { use } from 'chai';
|
2
|
+
import { stringify } from '@vitest/utils';
|
3
|
+
|
4
|
+
type Formatter = (input: string | number | null | undefined) => string;
|
5
|
+
|
6
|
+
declare const EXPECTED_COLOR: Formatter;
|
7
|
+
declare const RECEIVED_COLOR: Formatter;
|
8
|
+
declare const INVERTED_COLOR: Formatter;
|
9
|
+
declare const BOLD_WEIGHT: Formatter;
|
10
|
+
declare const DIM_COLOR: Formatter;
|
11
|
+
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
12
|
+
declare const printReceived: (object: unknown) => string;
|
13
|
+
declare const printExpected: (value: unknown) => string;
|
14
|
+
declare function diff(a: any, b: any, options?: DiffOptions): string;
|
15
|
+
|
16
|
+
declare const jestMatcherUtils_stringify: typeof stringify;
|
17
|
+
declare const jestMatcherUtils_EXPECTED_COLOR: typeof EXPECTED_COLOR;
|
18
|
+
declare const jestMatcherUtils_RECEIVED_COLOR: typeof RECEIVED_COLOR;
|
19
|
+
declare const jestMatcherUtils_INVERTED_COLOR: typeof INVERTED_COLOR;
|
20
|
+
declare const jestMatcherUtils_BOLD_WEIGHT: typeof BOLD_WEIGHT;
|
21
|
+
declare const jestMatcherUtils_DIM_COLOR: typeof DIM_COLOR;
|
22
|
+
declare const jestMatcherUtils_matcherHint: typeof matcherHint;
|
23
|
+
declare const jestMatcherUtils_printReceived: typeof printReceived;
|
24
|
+
declare const jestMatcherUtils_printExpected: typeof printExpected;
|
25
|
+
declare const jestMatcherUtils_diff: typeof diff;
|
26
|
+
declare namespace jestMatcherUtils {
|
27
|
+
export {
|
28
|
+
jestMatcherUtils_stringify as stringify,
|
29
|
+
jestMatcherUtils_EXPECTED_COLOR as EXPECTED_COLOR,
|
30
|
+
jestMatcherUtils_RECEIVED_COLOR as RECEIVED_COLOR,
|
31
|
+
jestMatcherUtils_INVERTED_COLOR as INVERTED_COLOR,
|
32
|
+
jestMatcherUtils_BOLD_WEIGHT as BOLD_WEIGHT,
|
33
|
+
jestMatcherUtils_DIM_COLOR as DIM_COLOR,
|
34
|
+
jestMatcherUtils_matcherHint as matcherHint,
|
35
|
+
jestMatcherUtils_printReceived as printReceived,
|
36
|
+
jestMatcherUtils_printExpected as printExpected,
|
37
|
+
jestMatcherUtils_diff as diff,
|
38
|
+
};
|
39
|
+
}
|
40
|
+
|
41
|
+
type FirstFunctionArgument<T> = T extends (arg: infer A) => unknown ? A : never;
|
42
|
+
type ChaiPlugin = FirstFunctionArgument<typeof use>;
|
43
|
+
type Tester = (a: any, b: any) => boolean | undefined;
|
44
|
+
interface MatcherHintOptions {
|
45
|
+
comment?: string;
|
46
|
+
expectedColor?: Formatter;
|
47
|
+
isDirectExpectCall?: boolean;
|
48
|
+
isNot?: boolean;
|
49
|
+
promise?: string;
|
50
|
+
receivedColor?: Formatter;
|
51
|
+
secondArgument?: string;
|
52
|
+
secondArgumentColor?: Formatter;
|
53
|
+
}
|
54
|
+
interface DiffOptions {
|
55
|
+
aAnnotation?: string;
|
56
|
+
aColor?: Formatter;
|
57
|
+
aIndicator?: string;
|
58
|
+
bAnnotation?: string;
|
59
|
+
bColor?: Formatter;
|
60
|
+
bIndicator?: string;
|
61
|
+
changeColor?: Formatter;
|
62
|
+
changeLineTrailingSpaceColor?: Formatter;
|
63
|
+
commonColor?: Formatter;
|
64
|
+
commonIndicator?: string;
|
65
|
+
commonLineTrailingSpaceColor?: Formatter;
|
66
|
+
contextLines?: number;
|
67
|
+
emptyFirstOrLastLinePlaceholder?: string;
|
68
|
+
expand?: boolean;
|
69
|
+
includeChangeCounts?: boolean;
|
70
|
+
omitAnnotationLines?: boolean;
|
71
|
+
patchColor?: Formatter;
|
72
|
+
compareKeys?: any;
|
73
|
+
}
|
74
|
+
interface MatcherState {
|
75
|
+
assertionCalls: number;
|
76
|
+
currentTestName?: string;
|
77
|
+
dontThrow?: () => void;
|
78
|
+
error?: Error;
|
79
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
80
|
+
expand?: boolean;
|
81
|
+
expectedAssertionsNumber?: number | null;
|
82
|
+
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
83
|
+
isExpectingAssertions?: boolean;
|
84
|
+
isExpectingAssertionsError?: Error | null;
|
85
|
+
isNot: boolean;
|
86
|
+
promise: string;
|
87
|
+
suppressedErrors: Array<Error>;
|
88
|
+
testPath?: string;
|
89
|
+
utils: typeof jestMatcherUtils & {
|
90
|
+
iterableEquality: Tester;
|
91
|
+
subsetEquality: Tester;
|
92
|
+
};
|
93
|
+
}
|
94
|
+
interface SyncExpectationResult {
|
95
|
+
pass: boolean;
|
96
|
+
message: () => string;
|
97
|
+
actual?: any;
|
98
|
+
expected?: any;
|
99
|
+
}
|
100
|
+
type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
101
|
+
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
102
|
+
interface RawMatcherFn<T extends MatcherState = MatcherState> {
|
103
|
+
(this: T, received: any, expected: any, options?: any): ExpectationResult;
|
104
|
+
}
|
105
|
+
type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
|
106
|
+
|
107
|
+
interface AsymmetricMatcherInterface {
|
108
|
+
asymmetricMatch(other: unknown): boolean;
|
109
|
+
toString(): string;
|
110
|
+
getExpectedType?(): string;
|
111
|
+
toAsymmetricMatcher?(): string;
|
112
|
+
}
|
113
|
+
declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
|
114
|
+
protected sample: T;
|
115
|
+
protected inverse: boolean;
|
116
|
+
$$typeof: symbol;
|
117
|
+
constructor(sample: T, inverse?: boolean);
|
118
|
+
protected getMatcherContext(expect?: Vi.ExpectStatic): State;
|
119
|
+
abstract asymmetricMatch(other: unknown): boolean;
|
120
|
+
abstract toString(): string;
|
121
|
+
getExpectedType?(): string;
|
122
|
+
toAsymmetricMatcher?(): string;
|
123
|
+
}
|
124
|
+
declare class StringContaining extends AsymmetricMatcher<string> {
|
125
|
+
constructor(sample: string, inverse?: boolean);
|
126
|
+
asymmetricMatch(other: string): boolean;
|
127
|
+
toString(): string;
|
128
|
+
getExpectedType(): string;
|
129
|
+
}
|
130
|
+
declare class Anything extends AsymmetricMatcher<void> {
|
131
|
+
asymmetricMatch(other: unknown): boolean;
|
132
|
+
toString(): string;
|
133
|
+
toAsymmetricMatcher(): string;
|
134
|
+
}
|
135
|
+
declare class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
|
136
|
+
constructor(sample: Record<string, unknown>, inverse?: boolean);
|
137
|
+
getPrototype(obj: object): any;
|
138
|
+
hasProperty(obj: object | null, property: string): boolean;
|
139
|
+
asymmetricMatch(other: any): boolean;
|
140
|
+
toString(): string;
|
141
|
+
getExpectedType(): string;
|
142
|
+
}
|
143
|
+
declare class ArrayContaining<T = unknown> extends AsymmetricMatcher<Array<T>> {
|
144
|
+
constructor(sample: Array<T>, inverse?: boolean);
|
145
|
+
asymmetricMatch(other: Array<T>): boolean;
|
146
|
+
toString(): string;
|
147
|
+
getExpectedType(): string;
|
148
|
+
}
|
149
|
+
declare class Any extends AsymmetricMatcher<any> {
|
150
|
+
constructor(sample: unknown);
|
151
|
+
fnNameFor(func: Function): string;
|
152
|
+
asymmetricMatch(other: unknown): boolean;
|
153
|
+
toString(): string;
|
154
|
+
getExpectedType(): string;
|
155
|
+
toAsymmetricMatcher(): string;
|
156
|
+
}
|
157
|
+
declare class StringMatching extends AsymmetricMatcher<RegExp> {
|
158
|
+
constructor(sample: string | RegExp, inverse?: boolean);
|
159
|
+
asymmetricMatch(other: string): boolean;
|
160
|
+
toString(): string;
|
161
|
+
getExpectedType(): string;
|
162
|
+
}
|
163
|
+
declare const JestAsymmetricMatchers: ChaiPlugin;
|
164
|
+
|
165
|
+
declare function equals(a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean): boolean;
|
166
|
+
declare function isAsymmetric(obj: any): boolean;
|
167
|
+
declare function hasAsymmetric(obj: any, seen?: Set<unknown>): boolean;
|
168
|
+
declare function isA(typeName: string, value: unknown): boolean;
|
169
|
+
declare function fnNameFor(func: Function): string;
|
170
|
+
declare function hasProperty(obj: object | null, property: string): boolean;
|
171
|
+
declare function isImmutableUnorderedKeyed(maybeKeyed: any): boolean;
|
172
|
+
declare function isImmutableUnorderedSet(maybeSet: any): boolean;
|
173
|
+
declare const iterableEquality: (a: any, b: any, aStack?: Array<any>, bStack?: Array<any>) => boolean | undefined;
|
174
|
+
declare const subsetEquality: (object: unknown, subset: unknown) => boolean | undefined;
|
175
|
+
declare const typeEquality: (a: any, b: any) => boolean | undefined;
|
176
|
+
declare const arrayBufferEquality: (a: unknown, b: unknown) => boolean | undefined;
|
177
|
+
declare const sparseArrayEquality: (a: unknown, b: unknown) => boolean | undefined;
|
178
|
+
declare const generateToBeMessage: (deepEqualityName: string, expected?: string, actual?: string) => string;
|
179
|
+
|
180
|
+
declare const MATCHERS_OBJECT: unique symbol;
|
181
|
+
declare const JEST_MATCHERS_OBJECT: unique symbol;
|
182
|
+
declare const GLOBAL_EXPECT: unique symbol;
|
183
|
+
|
184
|
+
declare const getState: <State extends MatcherState = MatcherState>(expect: Vi.ExpectStatic) => State;
|
185
|
+
declare const setState: <State extends MatcherState = MatcherState>(state: Partial<State>, expect: Vi.ExpectStatic) => void;
|
186
|
+
|
187
|
+
declare const JestChaiExpect: ChaiPlugin;
|
188
|
+
|
189
|
+
declare const JestExtend: ChaiPlugin;
|
190
|
+
|
191
|
+
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 };
|