1 | // Type definitions for Jasmine 3.8
|
---|
2 | // Project: http://jasmine.github.io
|
---|
3 | // Definitions by: Boris Yankov <https://github.com/borisyankov>
|
---|
4 | // Theodore Brown <https://github.com/theodorejb>
|
---|
5 | // David Pärsson <https://github.com/davidparsson>
|
---|
6 | // Lukas Zech <https://github.com/lukas-zech-software>
|
---|
7 | // Boris Breuer <https://github.com/Engineer2B>
|
---|
8 | // Chris Yungmann <https://github.com/cyungmann>
|
---|
9 | // Giles Roadnight <https://github.com/Roaders>
|
---|
10 | // Yaroslav Admin <https://github.com/devoto13>
|
---|
11 | // Domas Trijonis <https://github.com/fdim>
|
---|
12 | // Moshe Kolodny <https://github.com/kolodny>
|
---|
13 | // Stephen Farrar <https://github.com/stephenfarrar>
|
---|
14 | // Dominik Ehrenberg <https://github.com/djungowski>
|
---|
15 | // Chives <https://github.com/chivesrs>
|
---|
16 | // kirjs <https://github.com/kirjs>
|
---|
17 | // Md. Enzam Hossain <https://github.com/ienzam>
|
---|
18 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
---|
19 |
|
---|
20 | // For ddescribe / iit use : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * @deprecated Use {@link jasmine.ImplementationCallback} instead.
|
---|
24 | */
|
---|
25 | type ImplementationCallback = jasmine.ImplementationCallback;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Create a group of specs (often called a suite).
|
---|
29 | * @param description Textual description of the group
|
---|
30 | * @param specDefinitions Function for Jasmine to invoke that will define inner suites a specs
|
---|
31 | */
|
---|
32 | declare function describe(description: string, specDefinitions: () => void): void;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * A focused `describe`. If suites or specs are focused, only those that are focused will be executed.
|
---|
36 | * @param description Textual description of the group
|
---|
37 | * @param specDefinitions Function for Jasmine to invoke that will define inner suites a specs
|
---|
38 | */
|
---|
39 | declare function fdescribe(description: string, specDefinitions: () => void): void;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * A temporarily disabled `describe`. Specs within an xdescribe will be marked pending and not executed.
|
---|
43 | * @param description Textual description of the group
|
---|
44 | * @param specDefinitions Function for Jasmine to invoke that will define inner suites a specs
|
---|
45 | */
|
---|
46 | declare function xdescribe(description: string, specDefinitions: () => void): void;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Define a single spec. A spec should contain one or more expectations that test the state of the code.
|
---|
50 | * A spec whose expectations all succeed will be passing and a spec with any failures will fail.
|
---|
51 | * @param expectation Textual description of what this spec is checking
|
---|
52 | * @param assertion Function that contains the code of your test. If not provided the test will be pending.
|
---|
53 | * @param timeout Custom timeout for an async spec.
|
---|
54 | */
|
---|
55 | declare function it(expectation: string, assertion?: jasmine.ImplementationCallback, timeout?: number): void;
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * A focused `it`. If suites or specs are focused, only those that are focused will be executed.
|
---|
59 | * @param expectation Textual description of what this spec is checking
|
---|
60 | * @param assertion Function that contains the code of your test. If not provided the test will be pending.
|
---|
61 | * @param timeout Custom timeout for an async spec.
|
---|
62 | */
|
---|
63 | declare function fit(expectation: string, assertion?: jasmine.ImplementationCallback, timeout?: number): void;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * A temporarily disabled `it`. The spec will report as pending and will not be executed.
|
---|
67 | * @param expectation Textual description of what this spec is checking
|
---|
68 | * @param assertion Function that contains the code of your test. If not provided the test will be pending.
|
---|
69 | * @param timeout Custom timeout for an async spec.
|
---|
70 | */
|
---|
71 | declare function xit(expectation: string, assertion?: jasmine.ImplementationCallback, timeout?: number): void;
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Mark a spec as pending, expectation results will be ignored.
|
---|
75 | * If you call the function pending anywhere in the spec body, no matter the expectations, the spec will be marked pending.
|
---|
76 | * @param reason Reason the spec is pending.
|
---|
77 | */
|
---|
78 | declare function pending(reason?: string): void;
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Sets a user-defined property that will be provided to reporters as
|
---|
82 | * part of the properties field of SpecResult.
|
---|
83 | * @since 3.6.0
|
---|
84 | */
|
---|
85 | declare function setSpecProperty(key: string, value: unknown): void;
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Sets a user-defined property that will be provided to reporters as
|
---|
89 | * part of the properties field of SuiteResult.
|
---|
90 | * @since 3.6.0
|
---|
91 | */
|
---|
92 | declare function setSuiteProperty(key: string, value: unknown): void;
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Run some shared setup before each of the specs in the describe in which it is called.
|
---|
96 | * @param action Function that contains the code to setup your specs.
|
---|
97 | * @param timeout Custom timeout for an async beforeEach.
|
---|
98 | */
|
---|
99 | declare function beforeEach(action: jasmine.ImplementationCallback, timeout?: number): void;
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Run some shared teardown after each of the specs in the describe in which it is called.
|
---|
103 | * @param action Function that contains the code to teardown your specs.
|
---|
104 | * @param timeout Custom timeout for an async afterEach.
|
---|
105 | */
|
---|
106 | declare function afterEach(action: jasmine.ImplementationCallback, timeout?: number): void;
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Run some shared setup once before all of the specs in the describe are run.
|
---|
110 | * Note: Be careful, sharing the setup from a beforeAll makes it easy to accidentally leak state between your specs so that they erroneously pass or fail.
|
---|
111 | * @param action Function that contains the code to setup your specs.
|
---|
112 | * @param timeout Custom timeout for an async beforeAll.
|
---|
113 | */
|
---|
114 | declare function beforeAll(action: jasmine.ImplementationCallback, timeout?: number): void;
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Run some shared teardown once before all of the specs in the describe are run.
|
---|
118 | * Note: Be careful, sharing the teardown from a afterAll makes it easy to accidentally leak state between your specs so that they erroneously pass or fail.
|
---|
119 | * @param action Function that contains the code to teardown your specs.
|
---|
120 | * @param timeout Custom timeout for an async afterAll
|
---|
121 | */
|
---|
122 | declare function afterAll(action: jasmine.ImplementationCallback, timeout?: number): void;
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Create an expectation for a spec.
|
---|
126 | * @checkReturnValue see https://tsetse.info/check-return-value
|
---|
127 | * @param spy
|
---|
128 | */
|
---|
129 | declare function expect<T extends jasmine.Func>(spy: T | jasmine.Spy<T>): jasmine.FunctionMatchers<T>;
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Create an expectation for a spec.
|
---|
133 | * @checkReturnValue see https://tsetse.info/check-return-value
|
---|
134 | * @param actual
|
---|
135 | */
|
---|
136 | declare function expect<T>(actual: ArrayLike<T>): jasmine.ArrayLikeMatchers<T>;
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Create an expectation for a spec.
|
---|
140 | * @checkReturnValue see https://tsetse.info/check-return-value
|
---|
141 | * @param actual Actual computed value to test expectations against.
|
---|
142 | */
|
---|
143 | declare function expect<T>(actual: T): jasmine.Matchers<T>;
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Create an expectation for a spec.
|
---|
147 | */
|
---|
148 | declare function expect(): jasmine.NothingMatcher;
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Create an asynchronous expectation for a spec. Note that the matchers
|
---|
152 | * that are provided by an asynchronous expectation all return promises
|
---|
153 | * which must be either returned from the spec or waited for using `await`
|
---|
154 | * in order for Jasmine to associate them with the correct spec.
|
---|
155 | * @checkReturnValue see https://tsetse.info/check-return-value
|
---|
156 | * @param actual Actual computed value to test expectations against.
|
---|
157 | */
|
---|
158 | declare function expectAsync<T, U>(actual: T | PromiseLike<T>): jasmine.AsyncMatchers<T, U>;
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Explicitly mark a spec as failed.
|
---|
162 | * @param e Reason for the failure
|
---|
163 | */
|
---|
164 | declare function fail(e?: any): void;
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Action method that should be called when the async work is complete.
|
---|
168 | */
|
---|
169 | interface DoneFn extends Function {
|
---|
170 | (): void;
|
---|
171 |
|
---|
172 | /** fails the spec and indicates that it has completed. If the message is an Error, Error.message is used */
|
---|
173 | fail: (message?: Error | string) => void;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Install a spy onto an existing object.
|
---|
178 | * @param object The object upon which to install the `Spy`.
|
---|
179 | * @param method The name of the method to replace with a `Spy`.
|
---|
180 | */
|
---|
181 | declare function spyOn<T, K extends keyof T = keyof T>(
|
---|
182 | object: T,
|
---|
183 | method: T[K] extends Function ? K : never,
|
---|
184 | ): jasmine.Spy<
|
---|
185 | T[K] extends jasmine.Func ? T[K] : T[K] extends { new (...args: infer A): infer V } ? (...args: A) => V : never
|
---|
186 | >;
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Install a spy on a property installed with `Object.defineProperty` onto an existing object.
|
---|
190 | * @param object The object upon which to install the `Spy`.
|
---|
191 | * @param property The name of the property to replace with a `Spy`.
|
---|
192 | * @param accessType The access type (get|set) of the property to `Spy` on.
|
---|
193 | */
|
---|
194 | declare function spyOnProperty<T>(object: T, property: keyof T, accessType?: "get" | "set"): jasmine.Spy;
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Installs spies on all writable and configurable properties of an object.
|
---|
198 | * @param object The object upon which to install the `Spy`s.
|
---|
199 | * @param includeNonEnumerable Whether or not to add spies to non-enumerable properties.
|
---|
200 | */
|
---|
201 | declare function spyOnAllFunctions<T>(object: T, includeNonEnumerable?: boolean): jasmine.SpyObj<T>;
|
---|
202 |
|
---|
203 | declare namespace jasmine {
|
---|
204 | type Func = (...args: any[]) => any;
|
---|
205 |
|
---|
206 | // Use trick with prototype to allow abstract classes.
|
---|
207 | // More info: https://stackoverflow.com/a/38642922/2009373
|
---|
208 | type Constructor = Function & { prototype: any };
|
---|
209 |
|
---|
210 | type ImplementationCallback = (() => PromiseLike<any>) | (() => void) | ((done: DoneFn) => void);
|
---|
211 |
|
---|
212 | type ExpectedRecursive<T> =
|
---|
213 | | T
|
---|
214 | | ObjectContaining<T>
|
---|
215 | | AsymmetricMatcher<any>
|
---|
216 | | {
|
---|
217 | [K in keyof T]: ExpectedRecursive<T[K]> | Any;
|
---|
218 | };
|
---|
219 | type Expected<T> =
|
---|
220 | | T
|
---|
221 | | ObjectContaining<T>
|
---|
222 | | AsymmetricMatcher<any>
|
---|
223 | | Any
|
---|
224 | | Spy
|
---|
225 | | {
|
---|
226 | [K in keyof T]: ExpectedRecursive<T[K]>;
|
---|
227 | };
|
---|
228 | type SpyObjMethodNames<T = undefined> = T extends undefined
|
---|
229 | ? ReadonlyArray<string> | { [methodName: string]: any }
|
---|
230 | : ReadonlyArray<keyof T> | { [P in keyof T]?: T[P] extends Func ? ReturnType<T[P]> : any };
|
---|
231 |
|
---|
232 | type SpyObjPropertyNames<T = undefined> = T extends undefined
|
---|
233 | ? ReadonlyArray<string> | { [propertyName: string]: any }
|
---|
234 | : ReadonlyArray<keyof T> | { [P in keyof T]?: T[P] };
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure}
|
---|
238 | */
|
---|
239 | interface EnvConfiguration {
|
---|
240 | /**
|
---|
241 | * Whether to randomize spec execution order
|
---|
242 | * @since 3.3.0
|
---|
243 | * @default true
|
---|
244 | */
|
---|
245 | random?: boolean | undefined;
|
---|
246 | /**
|
---|
247 | * Seed to use as the basis of randomization.
|
---|
248 | * Null causes the seed to be determined randomly at the start of execution.
|
---|
249 | * @since 3.3.0
|
---|
250 | * @default null
|
---|
251 | */
|
---|
252 | seed?: number | string | undefined;
|
---|
253 | /**
|
---|
254 | * Whether to stop execution of the suite after the first spec failure
|
---|
255 | * @since 3.3.0
|
---|
256 | * @default false
|
---|
257 | */
|
---|
258 | failFast?: boolean | undefined;
|
---|
259 | /**
|
---|
260 | * Whether to fail the spec if it ran no expectations. By default
|
---|
261 | * a spec that ran no expectations is reported as passed. Setting this
|
---|
262 | * to true will report such spec as a failure.
|
---|
263 | * @since 3.5.0
|
---|
264 | * @default false
|
---|
265 | */
|
---|
266 | failSpecWithNoExpectations?: boolean | undefined;
|
---|
267 | /**
|
---|
268 | * Whether to cause specs to only have one expectation failure.
|
---|
269 | * @since 3.3.0
|
---|
270 | * @default false
|
---|
271 | */
|
---|
272 | oneFailurePerSpec?: boolean | undefined;
|
---|
273 | /**
|
---|
274 | * Function to use to filter specs
|
---|
275 | * @since 3.3.0
|
---|
276 | * @default true
|
---|
277 | */
|
---|
278 | specFilter?: Function | undefined;
|
---|
279 | /**
|
---|
280 | * Whether or not reporters should hide disabled specs from their output.
|
---|
281 | * Currently only supported by Jasmine's HTMLReporter
|
---|
282 | * @since 3.3.0
|
---|
283 | * @default false
|
---|
284 | */
|
---|
285 | hideDisabled?: boolean | undefined;
|
---|
286 | /**
|
---|
287 | * Set to provide a custom promise library that Jasmine will use if it needs
|
---|
288 | * to create a promise. If not set, it will default to whatever global Promise
|
---|
289 | * library is available (if any).
|
---|
290 | * @since 3.5.0
|
---|
291 | * @default undefined
|
---|
292 | */
|
---|
293 | Promise?: Function | undefined;
|
---|
294 | }
|
---|
295 |
|
---|
296 | function clock(): Clock;
|
---|
297 | function DiffBuilder(): DiffBuilder;
|
---|
298 |
|
---|
299 | var matchersUtil: MatchersUtil;
|
---|
300 |
|
---|
301 | /**
|
---|
302 | * That will succeed if the actual value being compared is an instance of the specified class/constructor.
|
---|
303 | */
|
---|
304 | function any(aclass: Constructor | Symbol): AsymmetricMatcher<any>;
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * That will succeed if the actual value being compared is not `null` and not `undefined`.
|
---|
308 | */
|
---|
309 | function anything(): AsymmetricMatcher<any>;
|
---|
310 |
|
---|
311 | /**
|
---|
312 | * That will succeed if the actual value being compared is `true` or anything truthy.
|
---|
313 | * @since 3.1.0
|
---|
314 | */
|
---|
315 | function truthy(): AsymmetricMatcher<any>;
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * That will succeed if the actual value being compared is `null`, `undefined`, `0`, `false` or anything falsey.
|
---|
319 | * @since 3.1.0
|
---|
320 | */
|
---|
321 | function falsy(): AsymmetricMatcher<any>;
|
---|
322 |
|
---|
323 | /**
|
---|
324 | * That will succeed if the actual value being compared is empty.
|
---|
325 | * @since 3.1.0
|
---|
326 | */
|
---|
327 | function empty(): AsymmetricMatcher<any>;
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * That will succeed if the actual value being compared is not empty.
|
---|
331 | * @since 3.1.0
|
---|
332 | */
|
---|
333 | function notEmpty(): AsymmetricMatcher<any>;
|
---|
334 |
|
---|
335 | function arrayContaining<T>(sample: ArrayLike<T>): ArrayContaining<T>;
|
---|
336 | function arrayWithExactContents<T>(sample: ArrayLike<T>): ArrayContaining<T>;
|
---|
337 | function objectContaining<T>(sample: { [K in keyof T]?: ExpectedRecursive<T[K]> }): ObjectContaining<T>;
|
---|
338 | function mapContaining<K, V>(sample: Map<K, V>): AsymmetricMatcher<Map<K, V>>;
|
---|
339 | function setContaining<T>(sample: Set<T>): AsymmetricMatcher<Set<T>>;
|
---|
340 |
|
---|
341 | function setDefaultSpyStrategy<Fn extends Func = Func>(fn?: (and: SpyAnd<Fn>) => void): void;
|
---|
342 | function addSpyStrategy<Fn extends Func = Func>(name: string, factory: Fn): void;
|
---|
343 | function createSpy<Fn extends Func>(name?: string, originalFn?: Fn): Spy<Fn>;
|
---|
344 | function createSpyObj(baseName: string, methodNames: SpyObjMethodNames, propertyNames?: SpyObjPropertyNames): any;
|
---|
345 | function createSpyObj<T>(
|
---|
346 | baseName: string,
|
---|
347 | methodNames: SpyObjMethodNames<T>,
|
---|
348 | propertyNames?: SpyObjPropertyNames<T>,
|
---|
349 | ): SpyObj<T>;
|
---|
350 | function createSpyObj(methodNames: SpyObjMethodNames, propertyNames?: SpyObjPropertyNames): any;
|
---|
351 | function createSpyObj<T>(methodNames: SpyObjMethodNames<T>, propertyNames?: SpyObjPropertyNames<T>): SpyObj<T>;
|
---|
352 |
|
---|
353 | function pp(value: any): string;
|
---|
354 |
|
---|
355 | function getEnv(): Env;
|
---|
356 |
|
---|
357 | function addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
|
---|
358 |
|
---|
359 | /**
|
---|
360 | * Add a custom object formatter for the current scope of specs.
|
---|
361 | * Note: This is only callable from within a beforeEach, it, or beforeAll.
|
---|
362 | * @since 3.6.0
|
---|
363 | * @see https://jasmine.github.io/tutorials/custom_object_formatters
|
---|
364 | */
|
---|
365 | function addCustomObjectFormatter(formatter: CustomObjectFormatter): void;
|
---|
366 |
|
---|
367 | function addMatchers(matchers: CustomMatcherFactories): void;
|
---|
368 | function addAsyncMatchers(matchers: CustomAsyncMatcherFactories): void;
|
---|
369 |
|
---|
370 | function stringMatching(str: string | RegExp): AsymmetricMatcher<string>;
|
---|
371 |
|
---|
372 | /**
|
---|
373 | * @deprecated Private method that may be changed or removed in the future
|
---|
374 | */
|
---|
375 | function formatErrorMsg(domain: string, usage: string): (msg: string) => string;
|
---|
376 |
|
---|
377 | interface Any extends AsymmetricMatcher<any> {
|
---|
378 | new (expectedClass: any): any;
|
---|
379 | jasmineToString(): string;
|
---|
380 | }
|
---|
381 |
|
---|
382 | interface AsymmetricMatcher<TValue> {
|
---|
383 | /**
|
---|
384 | * customTesters are deprecated and will be replaced with matcherUtils in the future.
|
---|
385 | */
|
---|
386 | asymmetricMatch(other: TValue, matchersUtil?: MatchersUtil | ReadonlyArray<CustomEqualityTester>): boolean;
|
---|
387 | jasmineToString?(): string;
|
---|
388 | }
|
---|
389 |
|
---|
390 | // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains()
|
---|
391 | interface ArrayLike<T> {
|
---|
392 | length: number;
|
---|
393 | [n: number]: T;
|
---|
394 | }
|
---|
395 |
|
---|
396 | interface ArrayContaining<T> extends AsymmetricMatcher<any> {
|
---|
397 | new?(sample: ArrayLike<T>): ArrayLike<T>;
|
---|
398 | jasmineToString(): string;
|
---|
399 | }
|
---|
400 |
|
---|
401 | interface ObjectContaining<T> extends AsymmetricMatcher<T> {
|
---|
402 | new?(sample: { [K in keyof T]?: any }): { [K in keyof T]?: any };
|
---|
403 |
|
---|
404 | jasmineToString?(): string;
|
---|
405 | }
|
---|
406 |
|
---|
407 | interface Clock {
|
---|
408 | install(): Clock;
|
---|
409 | uninstall(): void;
|
---|
410 | /** Calls to any registered callback are triggered when the clock is ticked forward via the jasmine.clock().tick function, which takes a number of milliseconds. */
|
---|
411 | tick(ms: number): void;
|
---|
412 | mockDate(date?: Date): void;
|
---|
413 | withMock(func: () => void): void;
|
---|
414 | }
|
---|
415 |
|
---|
416 | type CustomEqualityTester = (first: any, second: any) => boolean | void;
|
---|
417 |
|
---|
418 | type CustomObjectFormatter = (value: unknown) => string | undefined;
|
---|
419 |
|
---|
420 | interface CustomMatcher {
|
---|
421 | compare<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
|
---|
422 | compare(actual: any, ...expected: any[]): CustomMatcherResult;
|
---|
423 | negativeCompare?<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
|
---|
424 | negativeCompare?(actual: any, ...expected: any[]): CustomMatcherResult;
|
---|
425 | }
|
---|
426 |
|
---|
427 | interface CustomAsyncMatcher {
|
---|
428 | compare<T>(actual: T, expected: T, ...args: any[]): PromiseLike<CustomMatcherResult>;
|
---|
429 | compare(actual: any, ...expected: any[]): PromiseLike<CustomMatcherResult>;
|
---|
430 | negativeCompare?<T>(actual: T, expected: T, ...args: any[]): PromiseLike<CustomMatcherResult>;
|
---|
431 | negativeCompare?(actual: any, ...expected: any[]): PromiseLike<CustomMatcherResult>;
|
---|
432 | }
|
---|
433 |
|
---|
434 | type CustomMatcherFactory = (
|
---|
435 | util: MatchersUtil,
|
---|
436 | customEqualityTesters: ReadonlyArray<CustomEqualityTester>,
|
---|
437 | ) => CustomMatcher;
|
---|
438 |
|
---|
439 | type CustomAsyncMatcherFactory = (
|
---|
440 | util: MatchersUtil,
|
---|
441 | customEqualityTesters: ReadonlyArray<CustomEqualityTester>,
|
---|
442 | ) => CustomAsyncMatcher;
|
---|
443 |
|
---|
444 | interface CustomMatcherFactories {
|
---|
445 | [name: string]: CustomMatcherFactory;
|
---|
446 | }
|
---|
447 |
|
---|
448 | interface CustomAsyncMatcherFactories {
|
---|
449 | [name: string]: CustomAsyncMatcherFactory;
|
---|
450 | }
|
---|
451 |
|
---|
452 | interface CustomMatcherResult {
|
---|
453 | pass: boolean;
|
---|
454 | message?: string | undefined;
|
---|
455 | }
|
---|
456 |
|
---|
457 | interface DiffBuilder {
|
---|
458 | setRoots(actual: any, expected: any): void;
|
---|
459 | recordMismatch(formatter?: (actual: any, expected: any, path?: any, prettyPrinter?: any) => string): void;
|
---|
460 | withPath(pathComponent: string, block: () => void): void;
|
---|
461 | getMessage(): string;
|
---|
462 | }
|
---|
463 |
|
---|
464 | interface MatchersUtil {
|
---|
465 | equals(a: any, b: any, customTesters?: ReadonlyArray<CustomEqualityTester>, diffBuilder?: DiffBuilder): boolean;
|
---|
466 | contains<T>(
|
---|
467 | haystack: ArrayLike<T> | string,
|
---|
468 | needle: any,
|
---|
469 | customTesters?: ReadonlyArray<CustomEqualityTester>,
|
---|
470 | ): boolean;
|
---|
471 | buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: any[]): string;
|
---|
472 |
|
---|
473 | /**
|
---|
474 | * Formats a value for use in matcher failure messages and similar
|
---|
475 | * contexts, taking into account the current set of custom value
|
---|
476 | * formatters.
|
---|
477 | * @since 3.6.0
|
---|
478 | * @param value The value to pretty-print
|
---|
479 | * @return The pretty-printed value
|
---|
480 | */
|
---|
481 | pp: typeof pp;
|
---|
482 | }
|
---|
483 |
|
---|
484 | interface Env {
|
---|
485 | addReporter(reporter: CustomReporter): void;
|
---|
486 | allowRespy(allow: boolean): void;
|
---|
487 | clearReporters(): void;
|
---|
488 | configuration(): EnvConfiguration;
|
---|
489 | configure(configuration: EnvConfiguration): void;
|
---|
490 | execute(runnablesToRun?: Suite[], onComplete?: Func): void;
|
---|
491 | /**
|
---|
492 | * @deprecated Use hideDisabled option in {@link jasmine.Env.configure} instead.
|
---|
493 | */
|
---|
494 | hideDisabled(value: boolean): void;
|
---|
495 | /**
|
---|
496 | * @deprecated Check hideDisabled option in {@link jasmine.Env.configuration} instead.
|
---|
497 | */
|
---|
498 | hidingDisabled(): boolean;
|
---|
499 | provideFallbackReporter(reporter: CustomReporter): void;
|
---|
500 | /**
|
---|
501 | * @deprecated Check random option in {@link jasmine.Env.configuration} instead.
|
---|
502 | */
|
---|
503 | randomTests(): boolean;
|
---|
504 | /**
|
---|
505 | * @deprecated Use random option in {@link jasmine.Env.configure} instead.
|
---|
506 | */
|
---|
507 | randomizeTests(value: boolean): void;
|
---|
508 | /**
|
---|
509 | * @deprecated Use seed option in {@link jasmine.Env.configure} instead.
|
---|
510 | */
|
---|
511 | seed(value?: number | string): number | string;
|
---|
512 | /**
|
---|
513 | * Sets a user-defined property that will be provided to reporters as
|
---|
514 | * part of the properties field of SpecResult.
|
---|
515 | * @since 3.6.0
|
---|
516 | */
|
---|
517 | setSpecProperty: typeof setSpecProperty;
|
---|
518 | /**
|
---|
519 | * Sets a user-defined property that will be provided to reporters as
|
---|
520 | * part of the properties field of SuiteResult.
|
---|
521 | * @since 3.6.0
|
---|
522 | */
|
---|
523 | setSuiteProperty: typeof setSuiteProperty;
|
---|
524 | /**
|
---|
525 | * @deprecated Use specFilter option in {@link jasmine.Env.configure} instead.
|
---|
526 | */
|
---|
527 | specFilter(spec: Spec): boolean;
|
---|
528 | /**
|
---|
529 | * @deprecated Use failFast option in {@link jasmine.Env.configure} instead.
|
---|
530 | */
|
---|
531 | stopOnSpecFailure(value: boolean): void;
|
---|
532 | /**
|
---|
533 | * @deprecated Check failFast option in {@link jasmine.Env.configuration} instead.
|
---|
534 | */
|
---|
535 | stoppingOnSpecFailure(): boolean;
|
---|
536 | /**
|
---|
537 | * @deprecated Use oneFailurePerSpec option in {@link jasmine.Env.configure} instead.
|
---|
538 | */
|
---|
539 | throwOnExpectationFailure(value: boolean): void;
|
---|
540 | /**
|
---|
541 | * @deprecated Check oneFailurePerSpec option in {@link jasmine.Env.configuration} instead.
|
---|
542 | */
|
---|
543 | throwingExpectationFailures(): boolean;
|
---|
544 | topSuite(): Suite;
|
---|
545 | }
|
---|
546 |
|
---|
547 | interface HtmlReporter {
|
---|
548 | new (): any;
|
---|
549 | }
|
---|
550 |
|
---|
551 | interface HtmlSpecFilter {
|
---|
552 | new (): any;
|
---|
553 | }
|
---|
554 |
|
---|
555 | interface Result {
|
---|
556 | type: string;
|
---|
557 | }
|
---|
558 |
|
---|
559 | interface ExpectationResult extends Result {
|
---|
560 | matcherName: string;
|
---|
561 | message: string;
|
---|
562 | stack: string;
|
---|
563 | passed: boolean;
|
---|
564 | expected: any;
|
---|
565 | actual: any;
|
---|
566 | }
|
---|
567 |
|
---|
568 | interface DeprecationWarning extends Result {
|
---|
569 | message: string;
|
---|
570 | stack: string;
|
---|
571 | }
|
---|
572 |
|
---|
573 | interface Order {
|
---|
574 | new (options: { random: boolean; seed: number | string }): any;
|
---|
575 | random: boolean;
|
---|
576 | seed: number | string;
|
---|
577 | sort<T>(items: T[]): T[];
|
---|
578 | }
|
---|
579 |
|
---|
580 | namespace errors {
|
---|
581 | class ExpectationFailed extends Error {
|
---|
582 | constructor();
|
---|
583 |
|
---|
584 | stack: any;
|
---|
585 | }
|
---|
586 | }
|
---|
587 |
|
---|
588 | interface Matchers<T> {
|
---|
589 | /**
|
---|
590 | * Expect the actual value to be `===` to the expected value.
|
---|
591 | *
|
---|
592 | * @param expected The expected value to compare against.
|
---|
593 | * @example
|
---|
594 | * expect(thing).toBe(realThing);
|
---|
595 | */
|
---|
596 | toBe(expected: Expected<T>): void;
|
---|
597 | /**
|
---|
598 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
599 | */
|
---|
600 | // tslint:disable-next-line unified-signatures
|
---|
601 | toBe(expected: Expected<T>, expectationFailOutput: any): void;
|
---|
602 |
|
---|
603 | /**
|
---|
604 | * Expect the actual value to be equal to the expected, using deep equality comparison.
|
---|
605 | * @param expected Expected value.
|
---|
606 | * @example
|
---|
607 | * expect(bigObject).toEqual({ "foo": ['bar', 'baz'] });
|
---|
608 | */
|
---|
609 | toEqual(expected: Expected<T>): void;
|
---|
610 | /**
|
---|
611 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
612 | */
|
---|
613 | // tslint:disable-next-line unified-signatures
|
---|
614 | toEqual(expected: Expected<T>, expectationFailOutput: any): void;
|
---|
615 |
|
---|
616 | /**
|
---|
617 | * Expect the actual value to match a regular expression.
|
---|
618 | * @param expected Value to look for in the string.
|
---|
619 | * @example
|
---|
620 | * expect("my string").toMatch(/string$/);
|
---|
621 | * expect("other string").toMatch("her");
|
---|
622 | */
|
---|
623 | toMatch(expected: string | RegExp): void;
|
---|
624 | /**
|
---|
625 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
626 | */
|
---|
627 | // tslint:disable-next-line unified-signatures
|
---|
628 | toMatch(expected: string | RegExp, expectationFailOutput: any): void;
|
---|
629 |
|
---|
630 | toBeDefined(): void;
|
---|
631 | /**
|
---|
632 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
633 | */
|
---|
634 | // tslint:disable-next-line unified-signatures
|
---|
635 | toBeDefined(expectationFailOutput: any): void;
|
---|
636 | toBeUndefined(): void;
|
---|
637 | /**
|
---|
638 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
639 | */
|
---|
640 | // tslint:disable-next-line unified-signatures
|
---|
641 | toBeUndefined(expectationFailOutput: any): void;
|
---|
642 | toBeNull(): void;
|
---|
643 | /**
|
---|
644 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
645 | */
|
---|
646 | // tslint:disable-next-line unified-signatures
|
---|
647 | toBeNull(expectationFailOutput: any): void;
|
---|
648 | toBeNaN(): void;
|
---|
649 | toBeTruthy(): void;
|
---|
650 | /**
|
---|
651 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
652 | */
|
---|
653 | // tslint:disable-next-line unified-signatures
|
---|
654 | toBeTruthy(expectationFailOutput: any): void;
|
---|
655 | toBeFalsy(): void;
|
---|
656 | /**
|
---|
657 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
658 | */
|
---|
659 | // tslint:disable-next-line unified-signatures
|
---|
660 | toBeFalsy(expectationFailOutput: any): void;
|
---|
661 | toBeTrue(): void;
|
---|
662 | toBeFalse(): void;
|
---|
663 | toHaveBeenCalled(): void;
|
---|
664 | toHaveBeenCalledBefore(expected: Func): void;
|
---|
665 | toHaveBeenCalledWith(...params: any[]): void;
|
---|
666 | toHaveBeenCalledOnceWith(...params: any[]): void;
|
---|
667 | toHaveBeenCalledTimes(expected: number): void;
|
---|
668 | toContain(expected: any): void;
|
---|
669 | /**
|
---|
670 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
671 | */
|
---|
672 | // tslint:disable-next-line unified-signatures
|
---|
673 | toContain(expected: any, expectationFailOutput: any): void;
|
---|
674 | toBeLessThan(expected: number): void;
|
---|
675 | /**
|
---|
676 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
677 | */
|
---|
678 | // tslint:disable-next-line unified-signatures
|
---|
679 | toBeLessThan(expected: number, expectationFailOutput: any): void;
|
---|
680 | toBeLessThanOrEqual(expected: number): void;
|
---|
681 | /**
|
---|
682 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
683 | */
|
---|
684 | // tslint:disable-next-line unified-signatures
|
---|
685 | toBeLessThanOrEqual(expected: number, expectationFailOutput: any): void;
|
---|
686 | toBeGreaterThan(expected: number): void;
|
---|
687 | /**
|
---|
688 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
689 | */
|
---|
690 | // tslint:disable-next-line unified-signatures
|
---|
691 | toBeGreaterThan(expected: number, expectationFailOutput: any): void;
|
---|
692 | toBeGreaterThanOrEqual(expected: number): void;
|
---|
693 | /**
|
---|
694 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
695 | */
|
---|
696 | // tslint:disable-next-line unified-signatures
|
---|
697 | toBeGreaterThanOrEqual(expected: number, expectationFailOutput: any): void;
|
---|
698 | toBeCloseTo(expected: number, precision?: any): void;
|
---|
699 | /**
|
---|
700 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
701 | */
|
---|
702 | // tslint:disable-next-line unified-signatures
|
---|
703 | toBeCloseTo(expected: number, precision: any, expectationFailOutput: any): void;
|
---|
704 | toThrow(expected?: any): void;
|
---|
705 | toThrowError(message?: string | RegExp): void;
|
---|
706 | toThrowError(expected?: new (...args: any[]) => Error, message?: string | RegExp): void;
|
---|
707 | toThrowMatching(predicate: (thrown: any) => boolean): void;
|
---|
708 | toBeNegativeInfinity(): void;
|
---|
709 | /**
|
---|
710 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
711 | */
|
---|
712 | // tslint:disable-next-line unified-signatures
|
---|
713 | toBeNegativeInfinity(expectationFailOutput: any): void;
|
---|
714 | toBePositiveInfinity(): void;
|
---|
715 | /**
|
---|
716 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
717 | */
|
---|
718 | // tslint:disable-next-line unified-signatures
|
---|
719 | toBePositiveInfinity(expectationFailOutput: any): void;
|
---|
720 | toBeInstanceOf(expected: Constructor): void;
|
---|
721 |
|
---|
722 | /**
|
---|
723 | * Expect the actual value to be a DOM element that has the expected class.
|
---|
724 | * @since 3.0.0
|
---|
725 | * @param expected The class name to test for.
|
---|
726 | * @example
|
---|
727 | * var el = document.createElement('div');
|
---|
728 | * el.className = 'foo bar baz';
|
---|
729 | * expect(el).toHaveClass('bar');
|
---|
730 | */
|
---|
731 | toHaveClass(expected: string): void;
|
---|
732 | /**
|
---|
733 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
734 | */
|
---|
735 | // tslint:disable-next-line unified-signatures
|
---|
736 | toHaveClass(expected: string, expectationFailOutput: any): void;
|
---|
737 |
|
---|
738 | /**
|
---|
739 | * Expect the actual size to be equal to the expected, using array-like
|
---|
740 | * length or object keys size.
|
---|
741 | * @since 3.6.0
|
---|
742 | * @param expected The expected size
|
---|
743 | * @example
|
---|
744 | * array = [1,2];
|
---|
745 | * expect(array).toHaveSize(2);
|
---|
746 | */
|
---|
747 | toHaveSize(expected: number): void;
|
---|
748 |
|
---|
749 | /**
|
---|
750 | * Add some context for an expect.
|
---|
751 | * @param message Additional context to show when the matcher fails
|
---|
752 | * @checkReturnValue see https://tsetse.info/check-return-value
|
---|
753 | */
|
---|
754 | withContext(message: string): Matchers<T>;
|
---|
755 |
|
---|
756 | /**
|
---|
757 | * Invert the matcher following this expect.
|
---|
758 | */
|
---|
759 | not: Matchers<T>;
|
---|
760 | }
|
---|
761 |
|
---|
762 | interface ArrayLikeMatchers<T> extends Matchers<ArrayLike<T>> {
|
---|
763 | /**
|
---|
764 | * Expect the actual value to be `===` to the expected value.
|
---|
765 | *
|
---|
766 | * @param expected The expected value to compare against.
|
---|
767 | * @example
|
---|
768 | * expect(thing).toBe(realThing);
|
---|
769 | */
|
---|
770 | toBe(expected: Expected<ArrayLike<T>> | ArrayContaining<T>): void;
|
---|
771 | /**
|
---|
772 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
773 | */
|
---|
774 | // tslint:disable-next-line unified-signatures
|
---|
775 | toBe(expected: Expected<ArrayLike<T>> | ArrayContaining<T>, expectationFailOutput: any): void;
|
---|
776 |
|
---|
777 | /**
|
---|
778 | * Expect the actual value to be equal to the expected, using deep equality comparison.
|
---|
779 | * @param expected Expected value.
|
---|
780 | * @example
|
---|
781 | * expect(bigObject).toEqual({ "foo": ['bar', 'baz'] });
|
---|
782 | */
|
---|
783 | toEqual(expected: Expected<ArrayLike<T>> | ArrayContaining<T>): void;
|
---|
784 | /**
|
---|
785 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
786 | */
|
---|
787 | // tslint:disable-next-line unified-signatures
|
---|
788 | toEqual(expected: Expected<ArrayLike<T>> | ArrayContaining<T>, expectationFailOutput: any): void;
|
---|
789 |
|
---|
790 | toContain(expected: Expected<T>): void;
|
---|
791 | /**
|
---|
792 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
793 | */
|
---|
794 | // tslint:disable-next-line unified-signatures
|
---|
795 | toContain(expected: Expected<T>, expectationFailOutput: any): void;
|
---|
796 |
|
---|
797 | /**
|
---|
798 | * Add some context for an expect.
|
---|
799 | * @param message Additional context to show when the matcher fails.
|
---|
800 | * @checkReturnValue see https://tsetse.info/check-return-value
|
---|
801 | */
|
---|
802 | withContext(message: string): ArrayLikeMatchers<T>;
|
---|
803 |
|
---|
804 | /**
|
---|
805 | * Invert the matcher following this expect.
|
---|
806 | */
|
---|
807 | not: ArrayLikeMatchers<T>;
|
---|
808 | }
|
---|
809 |
|
---|
810 | type MatchableArgs<Fn> = Fn extends (...args: infer P) => any ? { [K in keyof P]: Expected<P[K]> } : never;
|
---|
811 |
|
---|
812 | interface FunctionMatchers<Fn extends Func> extends Matchers<any> {
|
---|
813 | /**
|
---|
814 | * Expects the actual (a spy) to have been called with the particular arguments at least once
|
---|
815 | * @param params The arguments to look for
|
---|
816 | */
|
---|
817 | toHaveBeenCalledWith(...params: MatchableArgs<Fn>): void;
|
---|
818 |
|
---|
819 | /**
|
---|
820 | * Expects the actual (a spy) to have been called exactly once, and exactly with the particular arguments
|
---|
821 | * @param params The arguments to look for
|
---|
822 | */
|
---|
823 | toHaveBeenCalledOnceWith(...params: MatchableArgs<Fn>): void;
|
---|
824 |
|
---|
825 | /**
|
---|
826 | * Add some context for an expect.
|
---|
827 | * @param message Additional context to show when the matcher fails.
|
---|
828 | * @checkReturnValue see https://tsetse.info/check-return-value
|
---|
829 | */
|
---|
830 | withContext(message: string): FunctionMatchers<Fn>;
|
---|
831 |
|
---|
832 | /**
|
---|
833 | * Invert the matcher following this expect.
|
---|
834 | */
|
---|
835 | not: FunctionMatchers<Fn>;
|
---|
836 | }
|
---|
837 |
|
---|
838 | interface NothingMatcher {
|
---|
839 | nothing(): void;
|
---|
840 | }
|
---|
841 |
|
---|
842 | interface AsyncMatchers<T, U> {
|
---|
843 | /**
|
---|
844 | * Expect a promise to be pending, i.e. the promise is neither resolved nor rejected.
|
---|
845 | */
|
---|
846 | toBePending(): PromiseLike<void>;
|
---|
847 | /**
|
---|
848 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
849 | */
|
---|
850 | // tslint:disable-next-line unified-signatures
|
---|
851 | toBePending(expectationFailOutput: any): PromiseLike<void>;
|
---|
852 |
|
---|
853 | /**
|
---|
854 | * Expect a promise to be resolved.
|
---|
855 | */
|
---|
856 | toBeResolved(): PromiseLike<void>;
|
---|
857 | /**
|
---|
858 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
859 | */
|
---|
860 | // tslint:disable-next-line unified-signatures
|
---|
861 | toBeResolved(expectationFailOutput: any): PromiseLike<void>;
|
---|
862 |
|
---|
863 | /**
|
---|
864 | * Expect a promise to be rejected.
|
---|
865 | */
|
---|
866 | toBeRejected(): PromiseLike<void>;
|
---|
867 | /**
|
---|
868 | * @deprecated expectationFailOutput is deprecated. Use withContext instead.
|
---|
869 | */
|
---|
870 | // tslint:disable-next-line unified-signatures
|
---|
871 | toBeRejected(expectationFailOutput: any): PromiseLike<void>;
|
---|
872 |
|
---|
873 | /**
|
---|
874 | * Expect a promise to be resolved to a value equal to the expected, using deep equality comparison.
|
---|
875 | * @param expected Value that the promise is expected to resolve to.
|
---|
876 | */
|
---|
877 | toBeResolvedTo(expected: Expected<T>): PromiseLike<void>;
|
---|
878 |
|
---|
879 | /**
|
---|
880 | * Expect a promise to be rejected with a value equal to the expected, using deep equality comparison.
|
---|
881 | * @param expected Value that the promise is expected to be rejected with.
|
---|
882 | */
|
---|
883 | toBeRejectedWith(expected: Expected<U>): PromiseLike<void>;
|
---|
884 |
|
---|
885 | /**
|
---|
886 | * Expect a promise to be rejected with a value matched to the expected.
|
---|
887 | * @param expected Error constructor the object that was thrown needs to be an instance of. If not provided, Error will be used.
|
---|
888 | * @param message The message that should be set on the thrown Error.
|
---|
889 | */
|
---|
890 | toBeRejectedWithError(expected?: new (...args: any[]) => Error, message?: string | RegExp): PromiseLike<void>;
|
---|
891 |
|
---|
892 | /**
|
---|
893 | * Expect a promise to be rejected with a value matched to the expected.
|
---|
894 | * @param message The message that should be set on the thrown Error.
|
---|
895 | */
|
---|
896 | toBeRejectedWithError(message?: string | RegExp): PromiseLike<void>;
|
---|
897 |
|
---|
898 | /**
|
---|
899 | * Add some context for an expect.
|
---|
900 | * @param message Additional context to show when the matcher fails.
|
---|
901 | * @checkReturnValue see https://tsetse.info/check-return-value
|
---|
902 | */
|
---|
903 | withContext(message: string): AsyncMatchers<T, U>;
|
---|
904 |
|
---|
905 | /**
|
---|
906 | * Fail as soon as possible if the actual is pending. Otherwise evaluate the matcher.
|
---|
907 | */
|
---|
908 | already: AsyncMatchers<T, U>;
|
---|
909 |
|
---|
910 | /**
|
---|
911 | * Invert the matcher following this expect.
|
---|
912 | */
|
---|
913 | not: AsyncMatchers<T, U>;
|
---|
914 | }
|
---|
915 |
|
---|
916 | interface JasmineStartedInfo {
|
---|
917 | totalSpecsDefined: number;
|
---|
918 | order: Order;
|
---|
919 | }
|
---|
920 |
|
---|
921 | interface CustomReportExpectation {
|
---|
922 | matcherName: string;
|
---|
923 | message: string;
|
---|
924 | passed: boolean;
|
---|
925 | stack: string;
|
---|
926 | }
|
---|
927 |
|
---|
928 | interface FailedExpectation extends CustomReportExpectation {
|
---|
929 | actual: string;
|
---|
930 | expected: string;
|
---|
931 | }
|
---|
932 |
|
---|
933 | interface PassedExpectation extends CustomReportExpectation {}
|
---|
934 |
|
---|
935 | interface DeprecatedExpectation {
|
---|
936 | message: string;
|
---|
937 | }
|
---|
938 |
|
---|
939 | interface SuiteResult {
|
---|
940 | /**
|
---|
941 | * The unique id of this spec.
|
---|
942 | */
|
---|
943 | id: string;
|
---|
944 |
|
---|
945 | /**
|
---|
946 | * The description passed to the {@link it} that created this spec.
|
---|
947 | */
|
---|
948 | description: string;
|
---|
949 |
|
---|
950 | /**
|
---|
951 | * The full description including all ancestors of this spec.
|
---|
952 | */
|
---|
953 | fullName: string;
|
---|
954 |
|
---|
955 | /**
|
---|
956 | * The list of expectations that failed during execution of this spec.
|
---|
957 | */
|
---|
958 | failedExpectations: FailedExpectation[];
|
---|
959 |
|
---|
960 | /**
|
---|
961 | * The list of deprecation warnings that occurred during execution this spec.
|
---|
962 | */
|
---|
963 | deprecationWarnings: DeprecatedExpectation[];
|
---|
964 |
|
---|
965 | /**
|
---|
966 | * Once the spec has completed, this string represents the pass/fail status of this spec.
|
---|
967 | */
|
---|
968 | status: string;
|
---|
969 |
|
---|
970 | /**
|
---|
971 | * The time in ms used by the spec execution, including any before/afterEach.
|
---|
972 | */
|
---|
973 | duration: number | null;
|
---|
974 |
|
---|
975 | /**
|
---|
976 | * User-supplied properties, if any, that were set using {@link Env.setSpecProperty}
|
---|
977 | */
|
---|
978 | properties: { [key: string]: unknown } | null;
|
---|
979 | }
|
---|
980 |
|
---|
981 | interface SpecResult extends SuiteResult {
|
---|
982 | /**
|
---|
983 | * The list of expectations that passed during execution of this spec.
|
---|
984 | */
|
---|
985 | passedExpectations: PassedExpectation[];
|
---|
986 |
|
---|
987 | /**
|
---|
988 | * If the spec is pending, this will be the reason.
|
---|
989 | */
|
---|
990 | pendingReason: string;
|
---|
991 | }
|
---|
992 |
|
---|
993 | interface JasmineDoneInfo {
|
---|
994 | overallStatus: string;
|
---|
995 | totalTime: number;
|
---|
996 | incompleteReason: string;
|
---|
997 | order: Order;
|
---|
998 | failedExpectations: ExpectationResult[];
|
---|
999 | deprecationWarnings: ExpectationResult[];
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | /** @deprecated use JasmineStartedInfo instead */
|
---|
1003 | type SuiteInfo = JasmineStartedInfo;
|
---|
1004 |
|
---|
1005 | /** @deprecated use SuiteResult or SpecResult instead */
|
---|
1006 | type CustomReporterResult = SuiteResult & SpecResult;
|
---|
1007 |
|
---|
1008 | /** @deprecated use JasmineDoneInfo instead */
|
---|
1009 | type RunDetails = JasmineDoneInfo;
|
---|
1010 |
|
---|
1011 | interface CustomReporter {
|
---|
1012 | jasmineStarted?(suiteInfo: JasmineStartedInfo, done?: () => void): void | Promise<void>;
|
---|
1013 | suiteStarted?(result: SuiteResult, done?: () => void): void | Promise<void>;
|
---|
1014 | specStarted?(result: SpecResult, done?: () => void): void | Promise<void>;
|
---|
1015 | specDone?(result: SpecResult, done?: () => void): void | Promise<void>;
|
---|
1016 | suiteDone?(result: SuiteResult, done?: () => void): void | Promise<void>;
|
---|
1017 | jasmineDone?(runDetails: JasmineDoneInfo, done?: () => void): void | Promise<void>;
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | type SpecFunction = (spec?: Spec) => void;
|
---|
1021 |
|
---|
1022 | interface Spec {
|
---|
1023 | new (attrs: any): any;
|
---|
1024 |
|
---|
1025 | id: number;
|
---|
1026 | env: Env;
|
---|
1027 | description: string;
|
---|
1028 | getFullName(): string;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | interface Suite extends Spec {
|
---|
1032 | parentSuite: Suite;
|
---|
1033 | children: Array<Spec | Suite>;
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | interface Spy<Fn extends Func = Func> {
|
---|
1037 | (...params: Parameters<Fn>): ReturnType<Fn>;
|
---|
1038 |
|
---|
1039 | and: SpyAnd<Fn>;
|
---|
1040 | calls: Calls<Fn>;
|
---|
1041 | withArgs(...args: MatchableArgs<Fn>): Spy<Fn>;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | type SpyObj<T> = T &
|
---|
1045 | {
|
---|
1046 | [K in keyof T]: T[K] extends Func ? T[K] & Spy<T[K]> : T[K];
|
---|
1047 | };
|
---|
1048 |
|
---|
1049 | /**
|
---|
1050 | * Determines whether the provided function is a Jasmine spy.
|
---|
1051 | * @since 2.0.0
|
---|
1052 | * @param putativeSpy The function to check.
|
---|
1053 | */
|
---|
1054 | function isSpy(putativeSpy: Func): putativeSpy is Spy;
|
---|
1055 |
|
---|
1056 | /**
|
---|
1057 | * It's like SpyObj, but doesn't verify argument/return types for functions.
|
---|
1058 | * Useful if TS cannot correctly infer type for complex objects.
|
---|
1059 | */
|
---|
1060 | type NonTypedSpyObj<T> = SpyObj<{ [K in keyof T]: T[K] extends Func ? Func : T[K] }>;
|
---|
1061 |
|
---|
1062 | /**
|
---|
1063 | * Obtains the promised type that a promise-returning function resolves to.
|
---|
1064 | */
|
---|
1065 | type PromisedReturnType<Fn extends Func> = Fn extends (...args: any[]) => PromiseLike<infer TResult>
|
---|
1066 | ? TResult
|
---|
1067 | : never;
|
---|
1068 |
|
---|
1069 | /**
|
---|
1070 | * Obtains the type that a promise-returning function can be rejected with.
|
---|
1071 | * This is so we can use .and.rejectWith() only for functions that return a promise.
|
---|
1072 | */
|
---|
1073 | type PromisedRejectType<Fn extends Function> = Fn extends (...args: any[]) => PromiseLike<unknown> ? any : never;
|
---|
1074 |
|
---|
1075 | interface SpyAnd<Fn extends Func> {
|
---|
1076 | identity: string;
|
---|
1077 |
|
---|
1078 | /** By chaining the spy with and.callThrough, the spy will still track all calls to it but in addition it will delegate to the actual implementation. */
|
---|
1079 | callThrough(): Spy<Fn>;
|
---|
1080 | /** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */
|
---|
1081 | returnValue(val: ReturnType<Fn>): Spy<Fn>;
|
---|
1082 | /** By chaining the spy with and.returnValues, all calls to the function will return specific values in order until it reaches the end of the return values list. */
|
---|
1083 | returnValues(...values: Array<ReturnType<Fn>>): Spy<Fn>;
|
---|
1084 | /** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */
|
---|
1085 | callFake(fn: Fn): Spy<Fn>;
|
---|
1086 | /** Tell the spy to return a promise resolving to the specified value when invoked. */
|
---|
1087 | resolveTo(val?: PromisedReturnType<Fn>): Spy<Fn>;
|
---|
1088 | /** Tell the spy to return a promise rejecting with the specified value when invoked. */
|
---|
1089 | rejectWith(val?: PromisedRejectType<Fn>): Spy<Fn>;
|
---|
1090 | /** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */
|
---|
1091 | throwError(msg: string | Error): Spy;
|
---|
1092 | /** When a calling strategy is used for a spy, the original stubbing behavior can be returned at any time with and.stub. */
|
---|
1093 | stub(): Spy;
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | interface Calls<Fn extends Func> {
|
---|
1097 | /** By chaining the spy with calls.any(), will return false if the spy has not been called at all, and then true once at least one call happens. */
|
---|
1098 | any(): boolean;
|
---|
1099 | /** By chaining the spy with calls.count(), will return the number of times the spy was called */
|
---|
1100 | count(): number;
|
---|
1101 | /** By chaining the spy with calls.argsFor(), will return the arguments passed to call number index */
|
---|
1102 | argsFor(index: number): Parameters<Fn>;
|
---|
1103 | /** By chaining the spy with calls.allArgs(), will return the arguments to all calls */
|
---|
1104 | allArgs(): ReadonlyArray<Parameters<Fn>>;
|
---|
1105 | /** By chaining the spy with calls.all(), will return the context (the this) and arguments passed all calls */
|
---|
1106 | all(): ReadonlyArray<CallInfo<Fn>>;
|
---|
1107 | /** By chaining the spy with calls.mostRecent(), will return the context (the this) and arguments for the most recent call */
|
---|
1108 | mostRecent(): CallInfo<Fn>;
|
---|
1109 | /** By chaining the spy with calls.first(), will return the context (the this) and arguments for the first call */
|
---|
1110 | first(): CallInfo<Fn>;
|
---|
1111 | /** By chaining the spy with calls.reset(), will clears all tracking for a spy */
|
---|
1112 | reset(): void;
|
---|
1113 | /** Set this spy to do a shallow clone of arguments passed to each invocation. */
|
---|
1114 | saveArgumentsByValue(): void;
|
---|
1115 | /** Get the "this" object that was passed to a specific invocation of this spy. */
|
---|
1116 | thisFor(index: number): any;
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | interface CallInfo<Fn extends Func> {
|
---|
1120 | /** The context (the this) for the call */
|
---|
1121 | object: any;
|
---|
1122 | /** All arguments passed to the call */
|
---|
1123 | args: Parameters<Fn>;
|
---|
1124 | /** The return value of the call */
|
---|
1125 | returnValue: ReturnType<Fn>;
|
---|
1126 | }
|
---|
1127 |
|
---|
1128 | interface Util {
|
---|
1129 | inherit(childClass: Function, parentClass: Function): any;
|
---|
1130 | formatException(e: any): any;
|
---|
1131 | htmlEscape(str: string): string;
|
---|
1132 | argsToArray(args: any): any;
|
---|
1133 | extend(destination: any, source: any): any;
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | interface JsApiReporter extends CustomReporter {
|
---|
1137 | new (): any;
|
---|
1138 |
|
---|
1139 | started: boolean;
|
---|
1140 | finished: boolean;
|
---|
1141 | runDetails: JasmineDoneInfo;
|
---|
1142 |
|
---|
1143 | status(): string;
|
---|
1144 | suiteResults(index: number, length: number): SuiteResult[];
|
---|
1145 | specResults(index: number, length: number): SpecResult[];
|
---|
1146 | suites(): { [id: string]: SuiteResult };
|
---|
1147 | specs(): SpecResult[];
|
---|
1148 | executionTime(): number;
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | interface Jasmine {
|
---|
1152 | Spec: Spec;
|
---|
1153 | clock: Clock;
|
---|
1154 | util: Util;
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | var HtmlReporter: HtmlReporter;
|
---|
1158 | var HtmlSpecFilter: HtmlSpecFilter;
|
---|
1159 |
|
---|
1160 | /**
|
---|
1161 | * Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
|
---|
1162 | */
|
---|
1163 | var DEFAULT_TIMEOUT_INTERVAL: number;
|
---|
1164 |
|
---|
1165 | /**
|
---|
1166 | * Maximum number of array elements to display when pretty printing objects.
|
---|
1167 | * This will also limit the number of keys and values displayed for an object.
|
---|
1168 | * Elements past this number will be ellipised.
|
---|
1169 | */
|
---|
1170 | var MAX_PRETTY_PRINT_ARRAY_LENGTH: number;
|
---|
1171 |
|
---|
1172 | /**
|
---|
1173 | * Maximum number of characters to display when pretty printing objects.
|
---|
1174 | * Characters past this number will be ellipised.
|
---|
1175 | */
|
---|
1176 | var MAX_PRETTY_PRINT_CHARS: number;
|
---|
1177 |
|
---|
1178 | /**
|
---|
1179 | * Maximum object depth the pretty printer will print to.
|
---|
1180 | * Set this to a lower value to speed up pretty printing if you have large objects.
|
---|
1181 | */
|
---|
1182 | var MAX_PRETTY_PRINT_DEPTH: number;
|
---|
1183 |
|
---|
1184 | var version: string;
|
---|
1185 |
|
---|
1186 | interface JasmineOptions {
|
---|
1187 | /**
|
---|
1188 | * The path to the project's base directory. This can be absolute or relative
|
---|
1189 | * to the current working directory. If it isn't specified, the current working
|
---|
1190 | * directory will be used.
|
---|
1191 | */
|
---|
1192 | projectBaseDir?: string;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | interface JasmineConfig {
|
---|
1196 | /**
|
---|
1197 | * Whether to fail specs that contain no expectations.
|
---|
1198 | * @default false
|
---|
1199 | */
|
---|
1200 | failSpecWithNoExpectations?: boolean;
|
---|
1201 | /**
|
---|
1202 | * An array of helper file paths or globs that match helper files. Each path or
|
---|
1203 | * glob will be evaluated relative to the spec directory. Helpers are loaded before specs.
|
---|
1204 | */
|
---|
1205 | helpers?: string[];
|
---|
1206 | /**
|
---|
1207 | * Specifies how to load files with names ending in .js. Valid values are
|
---|
1208 | * "require" and "import". "import" should be safe in all cases, and is
|
---|
1209 | * required if your project contains ES modules with filenames ending in .js.
|
---|
1210 | * @default "require"
|
---|
1211 | */
|
---|
1212 | jsLoader?: "require" | "import";
|
---|
1213 | /**
|
---|
1214 | * Whether to run specs in a random order.
|
---|
1215 | */
|
---|
1216 | random?: boolean;
|
---|
1217 | /**
|
---|
1218 | * An array of module names to load via require() at the start of execution.
|
---|
1219 | */
|
---|
1220 | requires?: string[];
|
---|
1221 | /**
|
---|
1222 | * The directory that spec files are contained in, relative to the project base directory.
|
---|
1223 | */
|
---|
1224 | spec_dir?: string;
|
---|
1225 | /**
|
---|
1226 | * An array of spec file paths or globs that match helper files. Each path
|
---|
1227 | * or glob will be evaluated relative to the spec directory.
|
---|
1228 | */
|
---|
1229 | spec_files?: string[];
|
---|
1230 | /**
|
---|
1231 | * Whether to stop suite execution on the first spec failure.
|
---|
1232 | */
|
---|
1233 | stopOnSpecFailure?: boolean;
|
---|
1234 | /**
|
---|
1235 | * Whether to stop each spec on the first expectation failure.
|
---|
1236 | */
|
---|
1237 | stopSpecOnExpectationFailure?: boolean;
|
---|
1238 | }
|
---|
1239 |
|
---|
1240 | interface DefaultReporterOptions {
|
---|
1241 | timer?: any;
|
---|
1242 | print?: (...args: any[]) => void;
|
---|
1243 | showColors?: boolean;
|
---|
1244 | jasmineCorePath?: string;
|
---|
1245 | }
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | declare module "jasmine" {
|
---|
1249 | class jasmine {
|
---|
1250 | jasmine: jasmine.Jasmine;
|
---|
1251 | env: jasmine.Env;
|
---|
1252 | reportersCount: number;
|
---|
1253 | completionReporter: jasmine.CustomReporter;
|
---|
1254 | reporter: jasmine.CustomReporter;
|
---|
1255 | showingColors: boolean;
|
---|
1256 | projectBaseDir: string;
|
---|
1257 | specDir: string;
|
---|
1258 | specFiles: string[];
|
---|
1259 | helperFiles: string[];
|
---|
1260 | requires: string[];
|
---|
1261 | onCompleteCallbackAdded: boolean;
|
---|
1262 | defaultReporterConfigured: boolean;
|
---|
1263 |
|
---|
1264 | constructor(options: jasmine.JasmineOptions);
|
---|
1265 | addMatchers(matchers: jasmine.CustomMatcherFactories): void;
|
---|
1266 | /**
|
---|
1267 | * Add a custom reporter to the Jasmine environment.
|
---|
1268 | */
|
---|
1269 | addReporter(reporter: jasmine.CustomReporter): void;
|
---|
1270 | /**
|
---|
1271 | * Adds a spec file to the list that will be loaded when the suite is executed.
|
---|
1272 | */
|
---|
1273 | addSpecFile(filePath: string): void;
|
---|
1274 | addSpecFiles(files: string[]): void;
|
---|
1275 | addHelperFiles(files: string[]): void;
|
---|
1276 | addRequires(files: string[]): void;
|
---|
1277 | /**
|
---|
1278 | * Configure the default reporter.
|
---|
1279 | */
|
---|
1280 | configureDefaultReporter(options: jasmine.DefaultReporterOptions): void;
|
---|
1281 | execute(files?: string[], filterString?: string): Promise<void>;
|
---|
1282 | exitCodeCompletion(passed: boolean): void;
|
---|
1283 | loadConfig(config: jasmine.JasmineConfig): void;
|
---|
1284 | loadConfigFile(configFilePath?: string): void;
|
---|
1285 | loadHelpers(): Promise<void>;
|
---|
1286 | loadSpecs(): Promise<void>;
|
---|
1287 | loadRequires(): void;
|
---|
1288 | onComplete(onCompleteCallback: (passed: boolean) => void): void;
|
---|
1289 | /**
|
---|
1290 | * Provide a fallback reporter if no other reporters have been specified.
|
---|
1291 | */
|
---|
1292 | provideFallbackReporter(reporter: jasmine.CustomReporter): void;
|
---|
1293 | /**
|
---|
1294 | * Clears all registered reporters.
|
---|
1295 | */
|
---|
1296 | clearReporters(): void;
|
---|
1297 | /**
|
---|
1298 | * Sets whether to randomize the order of specs.
|
---|
1299 | */
|
---|
1300 | randomizeTests(value: boolean): void;
|
---|
1301 | /**
|
---|
1302 | * Sets the random seed.
|
---|
1303 | */
|
---|
1304 | seed(value: number): void;
|
---|
1305 | /**
|
---|
1306 | * Sets whether to show colors in the console reporter.
|
---|
1307 | */
|
---|
1308 | showColors(value: boolean): void;
|
---|
1309 | stopSpecOnExpectationFailure(value: boolean): void;
|
---|
1310 | stopOnSpecFailure(value: boolean): void;
|
---|
1311 | static ConsoleReporter(): any;
|
---|
1312 |
|
---|
1313 | /**
|
---|
1314 | * The version of jasmine-core in use
|
---|
1315 | */
|
---|
1316 | coreVersion(): string;
|
---|
1317 | }
|
---|
1318 | export = jasmine;
|
---|
1319 | }
|
---|