1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import type {EqualsFunction} from '@jest/expect-utils';
|
8 | import type * as jestMatcherUtils from 'jest-matcher-utils';
|
9 | import {Tester} from '@jest/expect-utils';
|
10 | import {TesterContext} from '@jest/expect-utils';
|
11 |
|
12 | export declare abstract class AsymmetricMatcher<T>
|
13 | implements AsymmetricMatcher_2
|
14 | {
|
15 | protected sample: T;
|
16 | protected inverse: boolean;
|
17 | $$typeof: symbol;
|
18 | constructor(sample: T, inverse?: boolean);
|
19 | protected getMatcherContext(): MatcherContext;
|
20 | abstract asymmetricMatch(other: unknown): boolean;
|
21 | abstract toString(): string;
|
22 | getExpectedType?(): string;
|
23 | toAsymmetricMatcher?(): string;
|
24 | }
|
25 |
|
26 | declare type AsymmetricMatcher_2 = {
|
27 | asymmetricMatch(other: unknown): boolean;
|
28 | toString(): string;
|
29 | getExpectedType?(): string;
|
30 | toAsymmetricMatcher?(): string;
|
31 | };
|
32 |
|
33 | export declare interface AsymmetricMatchers {
|
34 | any(sample: unknown): AsymmetricMatcher_2;
|
35 | anything(): AsymmetricMatcher_2;
|
36 | arrayContaining(sample: Array<unknown>): AsymmetricMatcher_2;
|
37 | closeTo(sample: number, precision?: number): AsymmetricMatcher_2;
|
38 | objectContaining(sample: Record<string, unknown>): AsymmetricMatcher_2;
|
39 | stringContaining(sample: string): AsymmetricMatcher_2;
|
40 | stringMatching(sample: string | RegExp): AsymmetricMatcher_2;
|
41 | }
|
42 |
|
43 | export declare type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
44 |
|
45 | export declare interface BaseExpect {
|
46 | assertions(numberOfAssertions: number): void;
|
47 | addEqualityTesters(testers: Array<Tester>): void;
|
48 | extend(matchers: MatchersObject): void;
|
49 | extractExpectedAssertionsErrors(): ExpectedAssertionsErrors;
|
50 | getState(): MatcherState;
|
51 | hasAssertions(): void;
|
52 | setState(state: Partial<MatcherState>): void;
|
53 | }
|
54 |
|
55 | export declare type Expect = {
|
56 | <T = unknown>(actual: T): Matchers<void, T> &
|
57 | Inverse<Matchers<void, T>> &
|
58 | PromiseMatchers<T>;
|
59 | } & BaseExpect &
|
60 | AsymmetricMatchers &
|
61 | Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;
|
62 |
|
63 | declare const expect: Expect;
|
64 | export default expect;
|
65 | export {expect};
|
66 |
|
67 | export declare type ExpectationResult =
|
68 | | SyncExpectationResult
|
69 | | AsyncExpectationResult;
|
70 |
|
71 | declare type ExpectedAssertionsErrors = Array<{
|
72 | actual: string | number;
|
73 | error: Error;
|
74 | expected: string;
|
75 | }>;
|
76 |
|
77 | declare type Inverse<Matchers> = {
|
78 | |
79 |
|
80 |
|
81 | not: Matchers;
|
82 | };
|
83 |
|
84 | export declare class JestAssertionError extends Error {
|
85 | matcherResult?: Omit<SyncExpectationResult, 'message'> & {
|
86 | message: string;
|
87 | };
|
88 | }
|
89 |
|
90 | export declare type MatcherContext = MatcherUtils & Readonly<MatcherState>;
|
91 |
|
92 | export declare type MatcherFunction<Expected extends Array<unknown> = []> =
|
93 | MatcherFunctionWithContext<MatcherContext, Expected>;
|
94 |
|
95 | export declare type MatcherFunctionWithContext<
|
96 | Context extends MatcherContext = MatcherContext,
|
97 | Expected extends Array<any> = [] ,
|
98 | > = (
|
99 | this: Context,
|
100 | actual: unknown,
|
101 | ...expected: Expected
|
102 | ) => ExpectationResult;
|
103 |
|
104 | export declare interface Matchers<R extends void | Promise<void>, T = unknown> {
|
105 | |
106 |
|
107 |
|
108 | lastCalledWith(...expected: Array<unknown>): R;
|
109 | |
110 |
|
111 |
|
112 | lastReturnedWith(expected?: unknown): R;
|
113 | |
114 |
|
115 |
|
116 | nthCalledWith(nth: number, ...expected: Array<unknown>): R;
|
117 | |
118 |
|
119 |
|
120 | nthReturnedWith(nth: number, expected?: unknown): R;
|
121 | |
122 |
|
123 |
|
124 |
|
125 | toBe(expected: unknown): R;
|
126 | |
127 |
|
128 |
|
129 | toBeCalled(): R;
|
130 | |
131 |
|
132 |
|
133 | toBeCalledTimes(expected: number): R;
|
134 | |
135 |
|
136 |
|
137 | toBeCalledWith(...expected: Array<unknown>): R;
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 | toBeCloseTo(expected: number, precision?: number): R;
|
144 | |
145 |
|
146 |
|
147 | toBeDefined(): R;
|
148 | |
149 |
|
150 |
|
151 |
|
152 | toBeFalsy(): R;
|
153 | |
154 |
|
155 |
|
156 | toBeGreaterThan(expected: number | bigint): R;
|
157 | |
158 |
|
159 |
|
160 | toBeGreaterThanOrEqual(expected: number | bigint): R;
|
161 | |
162 |
|
163 |
|
164 |
|
165 | toBeInstanceOf(expected: unknown): R;
|
166 | |
167 |
|
168 |
|
169 | toBeLessThan(expected: number | bigint): R;
|
170 | |
171 |
|
172 |
|
173 | toBeLessThanOrEqual(expected: number | bigint): R;
|
174 | |
175 |
|
176 |
|
177 | toBeNaN(): R;
|
178 | |
179 |
|
180 |
|
181 |
|
182 | toBeNull(): R;
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 | toBeTruthy(): R;
|
189 | |
190 |
|
191 |
|
192 | toBeUndefined(): R;
|
193 | |
194 |
|
195 |
|
196 |
|
197 | toContain(expected: unknown): R;
|
198 | |
199 |
|
200 |
|
201 |
|
202 |
|
203 | toContainEqual(expected: unknown): R;
|
204 | |
205 |
|
206 |
|
207 |
|
208 | toEqual(expected: unknown): R;
|
209 | |
210 |
|
211 |
|
212 | toHaveBeenCalled(): R;
|
213 | |
214 |
|
215 |
|
216 | toHaveBeenCalledTimes(expected: number): R;
|
217 | |
218 |
|
219 |
|
220 | toHaveBeenCalledWith(...expected: Array<unknown>): R;
|
221 | |
222 |
|
223 |
|
224 | toHaveBeenNthCalledWith(nth: number, ...expected: Array<unknown>): R;
|
225 | |
226 |
|
227 |
|
228 |
|
229 | toHaveBeenLastCalledWith(...expected: Array<unknown>): R;
|
230 | |
231 |
|
232 |
|
233 |
|
234 |
|
235 | toHaveLastReturnedWith(expected?: unknown): R;
|
236 | |
237 |
|
238 |
|
239 |
|
240 | toHaveLength(expected: number): R;
|
241 | |
242 |
|
243 |
|
244 |
|
245 |
|
246 | toHaveNthReturnedWith(nth: number, expected?: unknown): R;
|
247 | |
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | toHaveProperty(
|
261 | expectedPath: string | Array<string>,
|
262 | expectedValue?: unknown,
|
263 | ): R;
|
264 | |
265 |
|
266 |
|
267 | toHaveReturned(): R;
|
268 | |
269 |
|
270 |
|
271 |
|
272 | toHaveReturnedTimes(expected: number): R;
|
273 | |
274 |
|
275 |
|
276 | toHaveReturnedWith(expected?: unknown): R;
|
277 | |
278 |
|
279 |
|
280 | toMatch(expected: string | RegExp): R;
|
281 | |
282 |
|
283 |
|
284 | toMatchObject(
|
285 | expected: Record<string, unknown> | Array<Record<string, unknown>>,
|
286 | ): R;
|
287 | |
288 |
|
289 |
|
290 | toReturn(): R;
|
291 | |
292 |
|
293 |
|
294 | toReturnTimes(expected: number): R;
|
295 | |
296 |
|
297 |
|
298 | toReturnWith(expected?: unknown): R;
|
299 | |
300 |
|
301 |
|
302 | toStrictEqual(expected: unknown): R;
|
303 | |
304 |
|
305 |
|
306 | toThrow(expected?: unknown): R;
|
307 | |
308 |
|
309 |
|
310 | toThrowError(expected?: unknown): R;
|
311 | }
|
312 |
|
313 | declare type MatchersObject = {
|
314 | [name: string]: RawMatcherFn;
|
315 | };
|
316 |
|
317 | export declare interface MatcherState {
|
318 | assertionCalls: number;
|
319 | currentConcurrentTestName?: () => string | undefined;
|
320 | currentTestName?: string;
|
321 | error?: Error;
|
322 | expand?: boolean;
|
323 | expectedAssertionsNumber: number | null;
|
324 | expectedAssertionsNumberError?: Error;
|
325 | isExpectingAssertions: boolean;
|
326 | isExpectingAssertionsError?: Error;
|
327 | isNot?: boolean;
|
328 | numPassingAsserts: number;
|
329 | promise?: string;
|
330 | suppressedErrors: Array<Error>;
|
331 | testPath?: string;
|
332 | }
|
333 |
|
334 | export declare interface MatcherUtils {
|
335 | customTesters: Array<Tester>;
|
336 | dontThrow(): void;
|
337 | equals: EqualsFunction;
|
338 | utils: typeof jestMatcherUtils & {
|
339 | iterableEquality: Tester;
|
340 | subsetEquality: Tester;
|
341 | };
|
342 | }
|
343 |
|
344 | declare type PromiseMatchers<T = unknown> = {
|
345 | |
346 |
|
347 |
|
348 |
|
349 | rejects: Matchers<Promise<void>, T> & Inverse<Matchers<Promise<void>, T>>;
|
350 | |
351 |
|
352 |
|
353 |
|
354 | resolves: Matchers<Promise<void>, T> & Inverse<Matchers<Promise<void>, T>>;
|
355 | };
|
356 |
|
357 | declare type RawMatcherFn<Context extends MatcherContext = MatcherContext> = {
|
358 | (this: Context, actual: any, ...expected: Array<any>): ExpectationResult;
|
359 | };
|
360 |
|
361 | export declare type SyncExpectationResult = {
|
362 | pass: boolean;
|
363 | message(): string;
|
364 | };
|
365 |
|
366 | export {Tester};
|
367 |
|
368 | export {TesterContext};
|
369 |
|
370 | export {};
|