UNPKG

37.6 kBTypeScriptView Raw
1// Type definitions for Jasmine 3.5
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// Gabe Moothart <https://github.com/gmoothart>
7// Lukas Zech <https://github.com/lukas-zech-software>
8// Boris Breuer <https://github.com/Engineer2B>
9// Chris Yungmann <https://github.com/cyungmann>
10// Giles Roadnight <https://github.com/Roaders>
11// Yaroslav Admin <https://github.com/devoto13>
12// Domas Trijonis <https://github.com/fdim>
13// Moshe Kolodny <https://github.com/kolodny>
14// Stephen Farrar <https://github.com/stephenfarrar>
15// Mochamad Arfin <https://github.com/ndunks>
16// Alex Povar <https://github.com/zvirja>
17// Dominik Ehrenberg <https://github.com/djungowski>
18// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
19// TypeScript Version: 2.8
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 */
25type 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 */
32declare 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 */
39declare 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 */
46declare 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 */
55declare 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 */
63declare 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 */
71declare 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 */
78declare function pending(reason?: string): void;
79
80/**
81 * Run some shared setup before each of the specs in the describe in which it is called.
82 * @param action Function that contains the code to setup your specs.
83 * @param timeout Custom timeout for an async beforeEach.
84 */
85declare function beforeEach(action: jasmine.ImplementationCallback, timeout?: number): void;
86
87/**
88 * Run some shared teardown after each of the specs in the describe in which it is called.
89 * @param action Function that contains the code to teardown your specs.
90 * @param timeout Custom timeout for an async afterEach.
91 */
92declare function afterEach(action: jasmine.ImplementationCallback, timeout?: number): void;
93
94/**
95 * Run some shared setup once before all of the specs in the describe are run.
96 * 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.
97 * @param action Function that contains the code to setup your specs.
98 * @param timeout Custom timeout for an async beforeAll.
99 */
100declare function beforeAll(action: jasmine.ImplementationCallback, timeout?: number): void;
101
102/**
103 * Run some shared teardown once before all of the specs in the describe are run.
104 * 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.
105 * @param action Function that contains the code to teardown your specs.
106 * @param timeout Custom timeout for an async afterAll
107 */
108declare function afterAll(action: jasmine.ImplementationCallback, timeout?: number): void;
109
110/**
111 * Create an expectation for a spec.
112 * @checkReturnValue see https://tsetse.info/check-return-value
113 * @param spy
114 */
115declare function expect(spy: Function): jasmine.Matchers<any>;
116
117/**
118 * Create an expectation for a spec.
119 * @checkReturnValue see https://tsetse.info/check-return-value
120 * @param actual
121 */
122declare function expect<T>(actual: ArrayLike<T>): jasmine.ArrayLikeMatchers<T>;
123
124/**
125 * Create an expectation for a spec.
126 * @checkReturnValue see https://tsetse.info/check-return-value
127 * @param actual Actual computed value to test expectations against.
128 */
129declare function expect<T>(actual: T): jasmine.Matchers<T>;
130
131/**
132 * Create an expectation for a spec.
133 */
134declare function expect(): jasmine.NothingMatcher;
135
136/**
137 * Create an asynchronous expectation for a spec. Note that the matchers
138 * that are provided by an asynchronous expectation all return promises
139 * which must be either returned from the spec or waited for using `await`
140 * in order for Jasmine to associate them with the correct spec.
141 * @checkReturnValue see https://tsetse.info/check-return-value
142 * @param actual - Actual computed value to test expectations against.
143 */
144declare function expectAsync<T, U>(actual: PromiseLike<T>): jasmine.AsyncMatchers<T, U>;
145
146/**
147 * Explicitly mark a spec as failed.
148 * @param e Reason for the failure
149 */
150declare function fail(e?: any): void;
151
152/**
153 * Action method that should be called when the async work is complete.
154 */
155interface DoneFn extends Function {
156 (): void;
157
158 /** fails the spec and indicates that it has completed. If the message is an Error, Error.message is used */
159 fail: (message?: Error | string) => void;
160}
161
162/**
163 * Install a spy onto an existing object.
164 * @param object The object upon which to install the `Spy`.
165 * @param method The name of the method to replace with a `Spy`.
166 */
167declare function spyOn<T>(object: T, method: keyof T): jasmine.Spy;
168
169/**
170 * Install a spy on a property installed with `Object.defineProperty` onto an existing object.
171 * @param object The object upon which to install the `Spy`.
172 * @param property The name of the property to replace with a `Spy`.
173 * @param accessType The access type (get|set) of the property to `Spy` on.
174 */
175declare function spyOnProperty<T>(object: T, property: keyof T, accessType?: 'get' | 'set'): jasmine.Spy;
176
177/**
178 * Installs spies on all writable and configurable properties of an object.
179 * @param object The object upon which to install the `Spy`s.
180 */
181declare function spyOnAllFunctions<T>(object: T): jasmine.SpyObj<T>;
182
183declare function runs(asyncMethod: Function): void;
184declare function waitsFor(latchMethod: () => boolean, failureMessage?: string, timeout?: number): void;
185declare function waits(timeout?: number): void;
186
187declare namespace jasmine {
188 type Func = (...args: any[]) => any;
189
190 // Use trick with prototype to allow abstract classes.
191 // More info: https://stackoverflow.com/a/38642922/2009373
192 type Constructor = Function & { prototype: any };
193
194 type ImplementationCallback = (() => PromiseLike<any>) | ((done: DoneFn) => void);
195
196 type ExpectedRecursive<T> = T | ObjectContaining<T> | AsymmetricMatcher<any> | {
197 [K in keyof T]: ExpectedRecursive<T[K]> | Any;
198 };
199 type Expected<T> = T | ObjectContaining<T> | AsymmetricMatcher<any> | Any | Spy | {
200 [K in keyof T]: ExpectedRecursive<T[K]>;
201 };
202 type SpyObjMethodNames<T = undefined> =
203 T extends undefined ?
204 (ReadonlyArray<string> | { [methodName: string]: any }) :
205 (ReadonlyArray<keyof T> | { [P in keyof T]?: T[P] extends Func ? ReturnType<T[P]> : any });
206
207 type SpyObjPropertyNames<T = undefined> =
208 T extends undefined ?
209 (ReadonlyArray<string> | { [propertyName: string]: any }) :
210 (ReadonlyArray<keyof T>);
211
212 /**
213 * Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure}
214 */
215 interface EnvConfiguration {
216 random?: boolean;
217 seed?: number;
218 failFast?: boolean;
219 failSpecWithNoExpectations?: boolean;
220 oneFailurePerSpec?: boolean;
221 hideDisabled?: boolean;
222 specFilter?: Function;
223 Promise?: Function;
224 }
225
226 function clock(): Clock;
227
228 var matchersUtil: MatchersUtil;
229
230 /**
231 * That will succeed if the actual value being compared is an instance of the specified class/constructor.
232 */
233 function any(aclass: Constructor | Symbol): AsymmetricMatcher<any>;
234
235 /**
236 * That will succeed if the actual value being compared is not `null` and not `undefined`.
237 */
238 function anything(): AsymmetricMatcher<any>;
239
240 /**
241 * That will succeed if the actual value being compared is `true` or anything truthy.
242 * @since 3.1.0
243 */
244 function truthy(): AsymmetricMatcher<any>;
245
246 /**
247 * That will succeed if the actual value being compared is `null`, `undefined`, `0`, `false` or anything falsey.
248 * @since 3.1.0
249 */
250 function falsy(): AsymmetricMatcher<any>;
251
252 /**
253 * That will succeed if the actual value being compared is empty.
254 * @since 3.1.0
255 */
256 function empty(): AsymmetricMatcher<any>;
257
258 /**
259 * That will succeed if the actual value being compared is not empty.
260 * @since 3.1.0
261 */
262 function notEmpty(): AsymmetricMatcher<any>;
263
264 function arrayContaining<T>(sample: ArrayLike<T>): ArrayContaining<T>;
265 function arrayWithExactContents<T>(sample: ArrayLike<T>): ArrayContaining<T>;
266 function objectContaining<T>(sample: Partial<T>): ObjectContaining<T>;
267
268 function setDefaultSpyStrategy(and: SpyAnd): void;
269 function createSpy(name?: string, originalFn?: Function): Spy;
270 function createSpyObj(baseName: string, methodNames: SpyObjMethodNames, propertyNames?: SpyObjPropertyNames): any;
271 function createSpyObj<T>(baseName: string, methodNames: SpyObjMethodNames<T>, propertyNames?: SpyObjPropertyNames<T>): SpyObj<T>;
272 function createSpyObj(methodNames: SpyObjMethodNames, propertyNames?: SpyObjPropertyNames): any;
273 function createSpyObj<T>(methodNames: SpyObjMethodNames<T>, propertyNames?: SpyObjPropertyNames<T>): SpyObj<T>;
274
275 function pp(value: any): string;
276
277 function getEnv(): Env;
278
279 function addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
280
281 function addMatchers(matchers: CustomMatcherFactories): void;
282 function addAsyncMatchers(matchers: CustomMatcherFactories): void;
283
284 function stringMatching(str: string | RegExp): AsymmetricMatcher<string>;
285
286 function formatErrorMsg(domain: string, usage: string): (msg: string) => string;
287
288 interface Any extends AsymmetricMatcher<any> {
289 (...params: any[]): any; // jasmine.Any can also be a function
290 new (expectedClass: any): any;
291
292 jasmineMatches(other: any): boolean;
293 jasmineToString(): string;
294 }
295
296 interface AsymmetricMatcher<TValue> {
297 asymmetricMatch(other: TValue, customTesters: ReadonlyArray<CustomEqualityTester>): boolean;
298 jasmineToString?(): string;
299 }
300
301 // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains()
302 interface ArrayLike<T> {
303 length: number;
304 [n: number]: T;
305 }
306
307 interface ArrayContaining<T> extends AsymmetricMatcher<any> {
308 new?(sample: ArrayLike<T>): ArrayLike<T>;
309 }
310
311 interface ObjectContaining<T> extends AsymmetricMatcher<any> {
312 new?(sample: {[K in keyof T]?: any}): {[K in keyof T]?: any};
313
314 jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean;
315 jasmineToString?(): string;
316 }
317
318 interface Block {
319 new (env: Env, func: SpecFunction, spec: Spec): any;
320
321 execute(onComplete: () => void): void;
322 }
323
324 interface WaitsBlock extends Block {
325 new (env: Env, timeout: number, spec: Spec): any;
326 }
327
328 interface WaitsForBlock extends Block {
329 new (env: Env, timeout: number, latchFunction: SpecFunction, message: string, spec: Spec): any;
330 }
331
332 interface Clock {
333 install(): void;
334 uninstall(): void;
335 /** 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. */
336 tick(ms: number): void;
337 mockDate(date?: Date): void;
338 withMock(func: () => void): void;
339 }
340
341 type CustomEqualityTester = (first: any, second: any) => boolean | void;
342
343 interface CustomMatcher {
344 compare<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
345 compare(actual: any, ...expected: any[]): CustomMatcherResult;
346 negativeCompare?<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
347 negativeCompare?(actual: any, ...expected: any[]): CustomMatcherResult;
348 }
349
350 type CustomMatcherFactory = (util: MatchersUtil, customEqualityTesters: ReadonlyArray<CustomEqualityTester>) => CustomMatcher;
351
352 interface CustomMatcherFactories {
353 [index: string]: CustomMatcherFactory;
354 }
355
356 interface CustomMatcherResult {
357 pass: boolean;
358 message?: string;
359 }
360
361 interface MatchersUtil {
362 equals(a: any, b: any, customTesters?: ReadonlyArray<CustomEqualityTester>): boolean;
363 contains<T>(haystack: ArrayLike<T> | string, needle: any, customTesters?: ReadonlyArray<CustomEqualityTester>): boolean;
364 buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: any[]): string;
365 }
366
367 interface Env {
368 currentSpec: Spec;
369
370 matchersClass: Matchers<any>;
371
372 version(): any;
373 versionString(): string;
374 nextSpecId(): number;
375 addReporter(reporter: Reporter | CustomReporter): void;
376 execute(): void;
377 describe(description: string, specDefinitions: () => void): Suite;
378 // ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these
379 beforeEach(beforeEachFunction: ImplementationCallback, timeout?: number): void;
380 beforeAll(beforeAllFunction: ImplementationCallback, timeout?: number): void;
381 currentRunner(): Runner;
382 afterEach(afterEachFunction: ImplementationCallback, timeout?: number): void;
383 afterAll(afterAllFunction: ImplementationCallback, timeout?: number): void;
384 xdescribe(desc: string, specDefinitions: () => void): XSuite;
385 it(description: string, func: () => void): Spec;
386 // iit(description: string, func: () => void): Spec; Not a part of jasmine. Angular team adds these
387 xit(desc: string, func: () => void): XSpec;
388 compareRegExps_(a: RegExp, b: RegExp, mismatchKeys: string[], mismatchValues: string[]): boolean;
389 compareObjects_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean;
390 equals_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean;
391 contains_(haystack: any, needle: any): boolean;
392 addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
393 addMatchers(matchers: CustomMatcherFactories): void;
394 specFilter(spec: Spec): boolean;
395 /**
396 * @deprecated Use oneFailurePerSpec option in {@link jasmine.Env.configure} instead.
397 */
398 throwOnExpectationFailure(value: boolean): void;
399 /**
400 * @deprecated Use failFast option in {@link jasmine.Env.configure} instead.
401 */
402 stopOnSpecFailure(value: boolean): void;
403 /**
404 * @deprecated Use seed option in {@link jasmine.Env.configure} instead.
405 */
406 seed(seed: string | number): string | number;
407 provideFallbackReporter(reporter: Reporter): void;
408 throwingExpectationFailures(): boolean;
409 allowRespy(allow: boolean): void;
410 randomTests(): boolean;
411 /**
412 * @deprecated Use random option in {@link jasmine.Env.configure} instead.
413 */
414 randomizeTests(b: boolean): void;
415 clearReporters(): void;
416 configure(configuration: EnvConfiguration): void;
417 }
418
419 interface FakeTimer {
420 new (): any;
421
422 reset(): void;
423 tick(millis: number): void;
424 runFunctionsWithinRange(oldMillis: number, nowMillis: number): void;
425 scheduleFunction(timeoutKey: any, funcToCall: () => void, millis: number, recurring: boolean): void;
426 }
427
428 interface HtmlReporter {
429 new (): any;
430 }
431
432 interface HtmlSpecFilter {
433 new (): any;
434 }
435
436 interface Result {
437 type: string;
438 }
439
440 interface NestedResults extends Result {
441 description: string;
442
443 totalCount: number;
444 passedCount: number;
445 failedCount: number;
446
447 skipped: boolean;
448
449 rollupCounts(result: NestedResults): void;
450 log(values: any): void;
451 getItems(): Result[];
452 addResult(result: Result): void;
453 passed(): boolean;
454 }
455
456 interface MessageResult extends Result {
457 values: any;
458 trace: Trace;
459 }
460
461 interface ExpectationResult extends Result {
462 matcherName: string;
463 passed(): boolean;
464 expected: any;
465 actual: any;
466 message: string;
467 trace: Trace;
468 }
469
470 interface Order {
471 new (options: { random: boolean, seed: string }): any;
472 random: boolean;
473 seed: string;
474 sort<T>(items: T[]): T[];
475 }
476
477 namespace errors {
478 class ExpectationFailed extends Error {
479 constructor();
480
481 stack: any;
482 }
483 }
484
485 interface TreeProcessor {
486 new (attrs: any): any;
487 execute: (done: Function) => void;
488 processTree(): any;
489 }
490
491 interface Trace {
492 name: string;
493 message: string;
494 stack: any;
495 }
496
497 interface PrettyPrinter {
498 new (): any;
499
500 format(value: any): void;
501 iterateObject(obj: any, fn: (property: string, isGetter: boolean) => void): void;
502 emitScalar(value: any): void;
503 emitString(value: string): void;
504 emitArray(array: any[]): void;
505 emitObject(obj: any): void;
506 append(value: any): void;
507 }
508
509 interface StringPrettyPrinter extends PrettyPrinter {
510 }
511
512 interface Queue {
513 new (env: any): any;
514
515 env: Env;
516 ensured: boolean[];
517 blocks: Block[];
518 running: boolean;
519 index: number;
520 offset: number;
521 abort: boolean;
522
523 addBefore(block: Block, ensure?: boolean): void;
524 add(block: any, ensure?: boolean): void;
525 insertNext(block: any, ensure?: boolean): void;
526 start(onComplete?: () => void): void;
527 isRunning(): boolean;
528 next_(): void;
529 results(): NestedResults;
530 }
531
532 interface Matchers<T> {
533 new (env: Env, actual: T, spec: Env, isNot?: boolean): any;
534
535 env: Env;
536 actual: T;
537 spec: Env;
538 isNot?: boolean;
539 message(): any;
540
541 /**
542 * Expect the actual value to be `===` to the expected value.
543 *
544 * @param expected - The expected value to compare against.
545 * @param expectationFailOutput
546 * @example
547 * expect(thing).toBe(realThing);
548 */
549 toBe(expected: Expected<T>, expectationFailOutput?: any): boolean;
550
551 /**
552 * Expect the actual value to be equal to the expected, using deep equality comparison.
553 * @param expected - Expected value.
554 * @param expectationFailOutput
555 * @example
556 * expect(bigObject).toEqual({ "foo": ['bar', 'baz'] });
557 */
558 toEqual(expected: Expected<T>, expectationFailOutput?: any): boolean;
559
560 /**
561 * Expect the actual value to match a regular expression.
562 * @param expected - Value to look for in the string.
563 * @example
564 * expect("my string").toMatch(/string$/);
565 * expect("other string").toMatch("her");
566 */
567 toMatch(expected: string | RegExp, expectationFailOutput?: any): boolean;
568
569 toBeDefined(expectationFailOutput?: any): boolean;
570 toBeUndefined(expectationFailOutput?: any): boolean;
571 toBeNull(expectationFailOutput?: any): boolean;
572 toBeNaN(): boolean;
573 toBeTruthy(expectationFailOutput?: any): boolean;
574 toBeFalsy(expectationFailOutput?: any): boolean;
575 toBeTrue(): boolean;
576 toBeFalse(): boolean;
577 toHaveBeenCalled(): boolean;
578 toHaveBeenCalledBefore(expected: Spy): boolean;
579 toHaveBeenCalledWith(...params: any[]): boolean;
580 toHaveBeenCalledTimes(expected: number): boolean;
581 toContain(expected: any, expectationFailOutput?: any): boolean;
582 toBeLessThan(expected: number, expectationFailOutput?: any): boolean;
583 toBeLessThanOrEqual(expected: number, expectationFailOutput?: any): boolean;
584 toBeGreaterThan(expected: number, expectationFailOutput?: any): boolean;
585 toBeGreaterThanOrEqual(expected: number, expectationFailOutput?: any): boolean;
586 toBeCloseTo(expected: number, precision?: any, expectationFailOutput?: any): boolean;
587 toThrow(expected?: any): boolean;
588 toThrowError(message?: string | RegExp): boolean;
589 toThrowError(expected?: new (...args: any[]) => Error, message?: string | RegExp): boolean;
590 toThrowMatching(predicate: (thrown: any) => boolean): boolean;
591 toBeNegativeInfinity(expectationFailOutput?: any): boolean;
592 toBePositiveInfinity(expectationFailOutput?: any): boolean;
593 toBeInstanceOf(expected: Constructor): boolean;
594
595 /**
596 * Expect the actual value to be a DOM element that has the expected class.
597 * @since 3.0.0
598 * @param expected - The class name to test for.
599 * @example
600 * var el = document.createElement('div');
601 * el.className = 'foo bar baz';
602 * expect(el).toHaveClass('bar');
603 */
604 toHaveClass(expected: string, expectationFailOutput?: any): boolean;
605
606 /**
607 * Add some context for an expect.
608 * @param message - Additional context to show when the matcher fails
609 */
610 withContext(message: string): Matchers<T>;
611
612 /**
613 * Invert the matcher following this expect.
614 */
615 not: Matchers<T>;
616 }
617
618 interface ArrayLikeMatchers<T> extends Matchers<ArrayLike<T>> {
619 /**
620 * Expect the actual value to be `===` to the expected value.
621 *
622 * @param expected - The expected value to compare against.
623 * @param expectationFailOutput
624 * @example
625 * expect(thing).toBe(realThing);
626 */
627 toBe(expected: Expected<ArrayLike<T>> | ArrayContaining<T>, expectationFailOutput?: any): boolean;
628
629 /**
630 * Expect the actual value to be equal to the expected, using deep equality comparison.
631 * @param expected - Expected value.
632 * @param expectationFailOutput
633 * @example
634 * expect(bigObject).toEqual({ "foo": ['bar', 'baz'] });
635 */
636 toEqual(expected: Expected<ArrayLike<T>> | ArrayContaining<T>, expectationFailOutput?: any): boolean;
637
638 toContain(expected: Expected<T>, expectationFailOutput?: any): boolean;
639
640 /**
641 * Add some context for an expect.
642 * @param message - Additional context to show when the matcher fails.
643 */
644 withContext(message: string): ArrayLikeMatchers<T>;
645
646 /**
647 * Invert the matcher following this expect.
648 */
649 not: ArrayLikeMatchers<T>;
650 }
651
652 interface NothingMatcher {
653 nothing(): void;
654 }
655
656 interface AsyncMatchers<T, U> {
657 /**
658 * Expect a promise to be resolved.
659 * @param expectationFailOutput
660 */
661 toBeResolved(expectationFailOutput?: any): PromiseLike<void>;
662
663 /**
664 * Expect a promise to be rejected.
665 * @param expectationFailOutput
666 */
667 toBeRejected(expectationFailOutput?: any): PromiseLike<void>;
668
669 /**
670 * Expect a promise to be resolved to a value equal to the expected, using deep equality comparison.
671 * @param expected - Value that the promise is expected to resolve to.
672 */
673 toBeResolvedTo(expected: Expected<T>): PromiseLike<void>;
674
675 /**
676 * Expect a promise to be rejected with a value equal to the expected, using deep equality comparison.
677 * @param expected - Value that the promise is expected to be rejected with.
678 */
679 toBeRejectedWith(expected: Expected<U>): PromiseLike<void>;
680
681 /**
682 * Expect a promise to be rejected with a value matched to the expected.
683 * @param expected - Error constructor the object that was thrown needs to be an instance of. If not provided, Error will be used.
684 * @param message - The message that should be set on the thrown Error.
685 */
686 toBeRejectedWithError(expected?: new (...args: any[]) => Error, message?: string | RegExp): PromiseLike<void>;
687
688 /**
689 * Expect a promise to be rejected with a value matched to the expected.
690 * @param message - The message that should be set on the thrown Error.
691 */
692 toBeRejectedWithError(message?: string | RegExp): PromiseLike<void>;
693
694 /**
695 * Add some context for an expect.
696 * @param message - Additional context to show when the matcher fails.
697 */
698 withContext(message: string): AsyncMatchers<T, U>;
699
700 /**
701 * Invert the matcher following this expect.
702 */
703 not: AsyncMatchers<T, U>;
704 }
705
706 interface Reporter {
707 reportRunnerStarting(runner: Runner): void;
708 reportRunnerResults(runner: Runner): void;
709 reportSuiteResults(suite: Suite): void;
710 reportSpecStarting(spec: Spec): void;
711 reportSpecResults(spec: Spec): void;
712 log(str: string): void;
713 }
714
715 interface MultiReporter extends Reporter {
716 addReporter(reporter: Reporter): void;
717 }
718
719 interface SuiteInfo {
720 totalSpecsDefined: number;
721 }
722
723 interface CustomReportExpectation {
724 matcherName: string;
725 message: string;
726 passed: boolean;
727 stack: string;
728 }
729
730 interface FailedExpectation extends CustomReportExpectation {
731 actual: string;
732 expected: string;
733 }
734
735 interface PassedExpectation extends CustomReportExpectation {
736 }
737
738 interface CustomReporterResult {
739 description: string;
740 failedExpectations?: FailedExpectation[];
741 fullName: string;
742 id: string;
743 passedExpectations?: PassedExpectation[];
744 pendingReason?: string;
745 status?: string;
746 }
747
748 interface RunDetails {
749 failedExpectations: ExpectationResult[];
750 order: Order;
751 }
752
753 interface CustomReporter {
754 jasmineStarted?(suiteInfo: SuiteInfo): void;
755 suiteStarted?(result: CustomReporterResult): void;
756 specStarted?(result: CustomReporterResult): void;
757 specDone?(result: CustomReporterResult): void;
758 suiteDone?(result: CustomReporterResult): void;
759 jasmineDone?(runDetails: RunDetails): void;
760 }
761
762 interface Runner {
763 new (env: Env): any;
764
765 execute(): void;
766 beforeEach(beforeEachFunction: SpecFunction): void;
767 afterEach(afterEachFunction: SpecFunction): void;
768 beforeAll(beforeAllFunction: SpecFunction): void;
769 afterAll(afterAllFunction: SpecFunction): void;
770 finishCallback(): void;
771 addSuite(suite: Suite): void;
772 add(block: Block): void;
773 specs(): Spec[];
774 suites(): Suite[];
775 topLevelSuites(): Suite[];
776 results(): NestedResults;
777 }
778
779 type SpecFunction = (spec?: Spec) => void;
780
781 interface SuiteOrSpec {
782 id: number;
783 env: Env;
784 description: string;
785 queue: Queue;
786 }
787
788 interface Spec extends SuiteOrSpec {
789 new (env: Env, suite: Suite, description: string): any;
790
791 suite: Suite;
792
793 afterCallbacks: SpecFunction[];
794 spies_: Spy[];
795
796 results_: NestedResults;
797 matchersClass: Matchers<any>;
798
799 getFullName(): string;
800 results(): NestedResults;
801 log(arguments: any): any;
802 runs(func: SpecFunction): Spec;
803 addToQueue(block: Block): void;
804 addMatcherResult(result: Result): void;
805 getResult(): any;
806 expect(actual: any): any;
807 waits(timeout: number): Spec;
808 waitsFor(latchFunction: SpecFunction, timeoutMessage?: string, timeout?: number): Spec;
809 fail(e?: any): void;
810 getMatchersClass_(): Matchers<any>;
811 addMatchers(matchersPrototype: CustomMatcherFactories): void;
812 finishCallback(): void;
813 finish(onComplete?: () => void): void;
814 after(doAfter: SpecFunction): void;
815 execute(onComplete?: () => void, enabled?: boolean): any;
816 addBeforesAndAftersToQueue(): void;
817 explodes(): void;
818 spyOn(obj: any, methodName: string, ignoreMethodDoesntExist: boolean): Spy;
819 spyOnProperty(object: any, property: string, accessType?: 'get' | 'set'): Spy;
820 spyOnAllFunctions(object: any): Spy;
821
822 removeAllSpies(): void;
823 throwOnExpectationFailure: boolean;
824 }
825
826 interface XSpec {
827 id: number;
828 runs(): void;
829 }
830
831 interface Suite extends SuiteOrSpec {
832 new (env: Env, description: string, specDefinitions: () => void, parentSuite: Suite): any;
833
834 parentSuite: Suite;
835
836 getFullName(): string;
837 finish(onComplete?: () => void): void;
838 beforeEach(beforeEachFunction: SpecFunction): void;
839 afterEach(afterEachFunction: SpecFunction): void;
840 beforeAll(beforeAllFunction: SpecFunction): void;
841 afterAll(afterAllFunction: SpecFunction): void;
842 results(): NestedResults;
843 add(suiteOrSpec: SuiteOrSpec): void;
844 specs(): Spec[];
845 suites(): Suite[];
846 children(): any[];
847 execute(onComplete?: () => void): void;
848 }
849
850 interface XSuite {
851 execute(): void;
852 }
853
854 interface Spy {
855 (...params: any[]): any;
856
857 and: SpyAnd;
858 calls: Calls;
859 withArgs(...args: any[]): Spy;
860 }
861
862 type SpyObj<T> = T & {
863 [K in keyof T]: T[K] extends Function ? T[K] & Spy : T[K];
864 };
865
866 interface SpyAnd {
867 identity: string;
868
869 /** 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. */
870 callThrough(): Spy;
871 /** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */
872 returnValue(val: any): Spy;
873 /** 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. */
874 returnValues(...values: any[]): Spy;
875 /** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */
876 callFake(fn: Function): Spy;
877 /** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */
878 throwError(msg: string|Error): Spy;
879 /** When a calling strategy is used for a spy, the original stubbing behavior can be returned at any time with and.stub. */
880 stub(): Spy;
881 }
882
883 interface Calls {
884 /** 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. */
885 any(): boolean;
886 /** By chaining the spy with calls.count(), will return the number of times the spy was called */
887 count(): number;
888 /** By chaining the spy with calls.argsFor(), will return the arguments passed to call number index */
889 argsFor(index: number): any[];
890 /** By chaining the spy with calls.allArgs(), will return the arguments to all calls */
891 allArgs(): any[];
892 /** By chaining the spy with calls.all(), will return the context (the this) and arguments passed all calls */
893 all(): CallInfo[];
894 /** By chaining the spy with calls.mostRecent(), will return the context (the this) and arguments for the most recent call */
895 mostRecent(): CallInfo;
896 /** By chaining the spy with calls.first(), will return the context (the this) and arguments for the first call */
897 first(): CallInfo;
898 /** By chaining the spy with calls.reset(), will clears all tracking for a spy */
899 reset(): void;
900 }
901
902 interface CallInfo {
903 /** The context (the this) for the call */
904 object: any;
905 /** All arguments passed to the call */
906 args: any[];
907 /** The return value of the call */
908 returnValue: any;
909 }
910
911 interface Util {
912 inherit(childClass: Function, parentClass: Function): any;
913 formatException(e: any): any;
914 htmlEscape(str: string): string;
915 argsToArray(args: any): any;
916 extend(destination: any, source: any): any;
917 }
918
919 interface JsApiReporter extends Reporter {
920 started: boolean;
921 finished: boolean;
922 result: any;
923 messages: any;
924 runDetails: RunDetails;
925
926 new (): any;
927
928 suites(): Suite[];
929 summarize_(suiteOrSpec: SuiteOrSpec): any;
930 results(): any;
931 resultsForSpec(specId: any): any;
932 log(str: any): any;
933 resultsForSpecs(specIds: any): any;
934 summarizeResult_(result: any): any;
935 }
936
937 interface Jasmine {
938 Spec: Spec;
939 clock: Clock;
940 util: Util;
941 }
942
943 var HtmlReporter: HtmlReporter;
944 var HtmlSpecFilter: HtmlSpecFilter;
945
946 /**
947 * Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
948 */
949 var DEFAULT_TIMEOUT_INTERVAL: number;
950
951 /**
952 * Maximum number of array elements to display when pretty printing objects.
953 * This will also limit the number of keys and values displayed for an object.
954 * Elements past this number will be ellipised.
955 */
956 var MAX_PRETTY_PRINT_ARRAY_LENGTH: number;
957
958 /**
959 * Maximum number of charasters to display when pretty printing objects.
960 * Characters past this number will be ellipised.
961 */
962 var MAX_PRETTY_PRINT_CHARS: number;
963
964 /**
965 * Maximum object depth the pretty printer will print to.
966 * Set this to a lower value to speed up pretty printing if you have large objects.
967 */
968 var MAX_PRETTY_PRINT_DEPTH: number;
969}
970
971declare module "jasmine" {
972 class jasmine {
973 constructor(options: any);
974 jasmine: jasmine.Jasmine;
975 addMatchers(matchers: jasmine.CustomMatcherFactories): void;
976 addReporter(reporter: jasmine.Reporter): void;
977 addSpecFile(filePath: string): void;
978 addSpecFiles(files: string[]): void;
979 configureDefaultReporter(options: any, ...args: any[]): void;
980 execute(files?: string[], filterString?: string): any;
981 exitCodeCompletion(passed: any): void;
982 loadConfig(config: any): void;
983 loadConfigFile(configFilePath: any): void;
984 loadHelpers(): void;
985 loadSpecs(): void;
986 onComplete(onCompleteCallback: (passed: boolean) => void): void;
987 provideFallbackReporter(reporter: jasmine.Reporter): void;
988 randomizeTests(value?: any): boolean;
989 seed(value: any): void;
990 showColors(value: any): void;
991 stopSpecOnExpectationFailure(value: any): void;
992 static ConsoleReporter(): any;
993 env: jasmine.Env;
994 reportersCount: number;
995 completionReporter: jasmine.CustomReporter;
996 reporter: jasmine.CustomReporter;
997 coreVersion(): string;
998 showingColors: boolean;
999 projectBaseDir: string;
1000 printDeprecation(): void;
1001 specFiles: string[];
1002 helperFiles: string[];
1003 }
1004 export = jasmine;
1005}