UNPKG

38.7 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// Alex Povar <https://github.com/zvirja>
16// Dominik Ehrenberg <https://github.com/djungowski>
17// Chives <https://github.com/chivesrs>
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: T|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> | { [P in keyof T]?: T[P] });
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: {[K in keyof T]?: ExpectedRecursive<T[K]>}): 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: CustomAsyncMatcherFactories): 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 interface CustomAsyncMatcher {
351 compare<T>(actual: T, expected: T, ...args: any[]): Promise<CustomMatcherResult>;
352 compare(actual: any, ...expected: any[]): Promise<CustomMatcherResult>;
353 negativeCompare?<T>(actual: T, expected: T, ...args: any[]): Promise<CustomMatcherResult>;
354 negativeCompare?(actual: any, ...expected: any[]): Promise<CustomMatcherResult>;
355 }
356
357 type CustomMatcherFactory = (util: MatchersUtil, customEqualityTesters: ReadonlyArray<CustomEqualityTester>) => CustomMatcher;
358
359 type CustomAsyncMatcherFactory = (util: MatchersUtil, customEqualityTesters: ReadonlyArray<CustomEqualityTester>) => CustomAsyncMatcher;
360
361 interface CustomMatcherFactories {
362 [name: string]: CustomMatcherFactory;
363 }
364
365 interface CustomAsyncMatcherFactories {
366 [name: string]: CustomAsyncMatcherFactory;
367 }
368
369 interface CustomMatcherResult {
370 pass: boolean;
371 message?: string;
372 }
373
374 interface MatchersUtil {
375 equals(a: any, b: any, customTesters?: ReadonlyArray<CustomEqualityTester>): boolean;
376 contains<T>(haystack: ArrayLike<T> | string, needle: any, customTesters?: ReadonlyArray<CustomEqualityTester>): boolean;
377 buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: any[]): string;
378 }
379
380 interface Env {
381 currentSpec: Spec;
382
383 matchersClass: Matchers<any>;
384
385 version(): any;
386 versionString(): string;
387 nextSpecId(): number;
388 addReporter(reporter: Reporter | CustomReporter): void;
389 execute(): void;
390 describe(description: string, specDefinitions: () => void): Suite;
391 // ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these
392 beforeEach(beforeEachFunction: ImplementationCallback, timeout?: number): void;
393 beforeAll(beforeAllFunction: ImplementationCallback, timeout?: number): void;
394 currentRunner(): Runner;
395 afterEach(afterEachFunction: ImplementationCallback, timeout?: number): void;
396 afterAll(afterAllFunction: ImplementationCallback, timeout?: number): void;
397 xdescribe(desc: string, specDefinitions: () => void): XSuite;
398 it(description: string, func: () => void): Spec;
399 // iit(description: string, func: () => void): Spec; Not a part of jasmine. Angular team adds these
400 xit(desc: string, func: () => void): XSpec;
401 compareRegExps_(a: RegExp, b: RegExp, mismatchKeys: string[], mismatchValues: string[]): boolean;
402 compareObjects_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean;
403 equals_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean;
404 contains_(haystack: any, needle: any): boolean;
405 addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
406 addMatchers(matchers: CustomMatcherFactories): void;
407 specFilter(spec: Spec): boolean;
408 /**
409 * @deprecated Use oneFailurePerSpec option in {@link jasmine.Env.configure} instead.
410 */
411 throwOnExpectationFailure(value: boolean): void;
412 /**
413 * @deprecated Use failFast option in {@link jasmine.Env.configure} instead.
414 */
415 stopOnSpecFailure(value: boolean): void;
416 /**
417 * @deprecated Use seed option in {@link jasmine.Env.configure} instead.
418 */
419 seed(seed: string | number): string | number;
420 provideFallbackReporter(reporter: Reporter): void;
421 throwingExpectationFailures(): boolean;
422 allowRespy(allow: boolean): void;
423 randomTests(): boolean;
424 /**
425 * @deprecated Use random option in {@link jasmine.Env.configure} instead.
426 */
427 randomizeTests(b: boolean): void;
428 clearReporters(): void;
429 configure(configuration: EnvConfiguration): void;
430 }
431
432 interface FakeTimer {
433 new (): any;
434
435 reset(): void;
436 tick(millis: number): void;
437 runFunctionsWithinRange(oldMillis: number, nowMillis: number): void;
438 scheduleFunction(timeoutKey: any, funcToCall: () => void, millis: number, recurring: boolean): void;
439 }
440
441 interface HtmlReporter {
442 new (): any;
443 }
444
445 interface HtmlSpecFilter {
446 new (): any;
447 }
448
449 interface Result {
450 type: string;
451 }
452
453 interface NestedResults extends Result {
454 description: string;
455
456 totalCount: number;
457 passedCount: number;
458 failedCount: number;
459
460 skipped: boolean;
461
462 rollupCounts(result: NestedResults): void;
463 log(values: any): void;
464 getItems(): Result[];
465 addResult(result: Result): void;
466 passed(): boolean;
467 }
468
469 interface MessageResult extends Result {
470 values: any;
471 trace: Trace;
472 }
473
474 interface ExpectationResult extends Result {
475 matcherName: string;
476 passed(): boolean;
477 expected: any;
478 actual: any;
479 message: string;
480 trace: Trace;
481 }
482
483 interface Order {
484 new (options: { random: boolean, seed: string }): any;
485 random: boolean;
486 seed: string;
487 sort<T>(items: T[]): T[];
488 }
489
490 namespace errors {
491 class ExpectationFailed extends Error {
492 constructor();
493
494 stack: any;
495 }
496 }
497
498 interface TreeProcessor {
499 new (attrs: any): any;
500 execute: (done: Function) => void;
501 processTree(): any;
502 }
503
504 interface Trace {
505 name: string;
506 message: string;
507 stack: any;
508 }
509
510 interface PrettyPrinter {
511 new (): any;
512
513 format(value: any): void;
514 iterateObject(obj: any, fn: (property: string, isGetter: boolean) => void): void;
515 emitScalar(value: any): void;
516 emitString(value: string): void;
517 emitArray(array: any[]): void;
518 emitObject(obj: any): void;
519 append(value: any): void;
520 }
521
522 interface StringPrettyPrinter extends PrettyPrinter {
523 }
524
525 interface Queue {
526 new (env: any): any;
527
528 env: Env;
529 ensured: boolean[];
530 blocks: Block[];
531 running: boolean;
532 index: number;
533 offset: number;
534 abort: boolean;
535
536 addBefore(block: Block, ensure?: boolean): void;
537 add(block: any, ensure?: boolean): void;
538 insertNext(block: any, ensure?: boolean): void;
539 start(onComplete?: () => void): void;
540 isRunning(): boolean;
541 next_(): void;
542 results(): NestedResults;
543 }
544
545 interface Matchers<T> {
546 new (env: Env, actual: T, spec: Env, isNot?: boolean): any;
547
548 env: Env;
549 actual: T;
550 spec: Env;
551 isNot?: boolean;
552 message(): any;
553
554 /**
555 * Expect the actual value to be `===` to the expected value.
556 *
557 * @param expected - The expected value to compare against.
558 * @param expectationFailOutput
559 * @example
560 * expect(thing).toBe(realThing);
561 */
562 toBe(expected: Expected<T>, expectationFailOutput?: any): boolean;
563
564 /**
565 * Expect the actual value to be equal to the expected, using deep equality comparison.
566 * @param expected - Expected value.
567 * @param expectationFailOutput
568 * @example
569 * expect(bigObject).toEqual({ "foo": ['bar', 'baz'] });
570 */
571 toEqual(expected: Expected<T>, expectationFailOutput?: any): boolean;
572
573 /**
574 * Expect the actual value to match a regular expression.
575 * @param expected - Value to look for in the string.
576 * @example
577 * expect("my string").toMatch(/string$/);
578 * expect("other string").toMatch("her");
579 */
580 toMatch(expected: string | RegExp, expectationFailOutput?: any): boolean;
581
582 toBeDefined(expectationFailOutput?: any): boolean;
583 toBeUndefined(expectationFailOutput?: any): boolean;
584 toBeNull(expectationFailOutput?: any): boolean;
585 toBeNaN(): boolean;
586 toBeTruthy(expectationFailOutput?: any): boolean;
587 toBeFalsy(expectationFailOutput?: any): boolean;
588 toBeTrue(): boolean;
589 toBeFalse(): boolean;
590 toHaveBeenCalled(): boolean;
591 toHaveBeenCalledBefore(expected: Spy): boolean;
592 toHaveBeenCalledWith(...params: any[]): boolean;
593 toHaveBeenCalledTimes(expected: number): boolean;
594 toContain(expected: any, expectationFailOutput?: any): boolean;
595 toBeLessThan(expected: number, expectationFailOutput?: any): boolean;
596 toBeLessThanOrEqual(expected: number, expectationFailOutput?: any): boolean;
597 toBeGreaterThan(expected: number, expectationFailOutput?: any): boolean;
598 toBeGreaterThanOrEqual(expected: number, expectationFailOutput?: any): boolean;
599 toBeCloseTo(expected: number, precision?: any, expectationFailOutput?: any): boolean;
600 toThrow(expected?: any): boolean;
601 toThrowError(message?: string | RegExp): boolean;
602 toThrowError(expected?: new (...args: any[]) => Error, message?: string | RegExp): boolean;
603 toThrowMatching(predicate: (thrown: any) => boolean): boolean;
604 toBeNegativeInfinity(expectationFailOutput?: any): boolean;
605 toBePositiveInfinity(expectationFailOutput?: any): boolean;
606 toBeInstanceOf(expected: Constructor): boolean;
607
608 /**
609 * Expect the actual value to be a DOM element that has the expected class.
610 * @since 3.0.0
611 * @param expected - The class name to test for.
612 * @example
613 * var el = document.createElement('div');
614 * el.className = 'foo bar baz';
615 * expect(el).toHaveClass('bar');
616 */
617 toHaveClass(expected: string, expectationFailOutput?: any): boolean;
618
619 /**
620 * Add some context for an expect.
621 * @param message - Additional context to show when the matcher fails
622 */
623 withContext(message: string): Matchers<T>;
624
625 /**
626 * Invert the matcher following this expect.
627 */
628 not: Matchers<T>;
629 }
630
631 interface ArrayLikeMatchers<T> extends Matchers<ArrayLike<T>> {
632 /**
633 * Expect the actual value to be `===` to the expected value.
634 *
635 * @param expected - The expected value to compare against.
636 * @param expectationFailOutput
637 * @example
638 * expect(thing).toBe(realThing);
639 */
640 toBe(expected: Expected<ArrayLike<T>> | ArrayContaining<T>, expectationFailOutput?: any): boolean;
641
642 /**
643 * Expect the actual value to be equal to the expected, using deep equality comparison.
644 * @param expected - Expected value.
645 * @param expectationFailOutput
646 * @example
647 * expect(bigObject).toEqual({ "foo": ['bar', 'baz'] });
648 */
649 toEqual(expected: Expected<ArrayLike<T>> | ArrayContaining<T>, expectationFailOutput?: any): boolean;
650
651 toContain(expected: Expected<T>, expectationFailOutput?: any): boolean;
652
653 /**
654 * Add some context for an expect.
655 * @param message - Additional context to show when the matcher fails.
656 */
657 withContext(message: string): ArrayLikeMatchers<T>;
658
659 /**
660 * Invert the matcher following this expect.
661 */
662 not: ArrayLikeMatchers<T>;
663 }
664
665 interface NothingMatcher {
666 nothing(): void;
667 }
668
669 interface AsyncMatchers<T, U> {
670 /**
671 * Expect a promise to be resolved.
672 * @param expectationFailOutput
673 */
674 toBeResolved(expectationFailOutput?: any): PromiseLike<void>;
675
676 /**
677 * Expect a promise to be rejected.
678 * @param expectationFailOutput
679 */
680 toBeRejected(expectationFailOutput?: any): PromiseLike<void>;
681
682 /**
683 * Expect a promise to be resolved to a value equal to the expected, using deep equality comparison.
684 * @param expected - Value that the promise is expected to resolve to.
685 */
686 toBeResolvedTo(expected: Expected<T>): PromiseLike<void>;
687
688 /**
689 * Expect a promise to be rejected with a value equal to the expected, using deep equality comparison.
690 * @param expected - Value that the promise is expected to be rejected with.
691 */
692 toBeRejectedWith(expected: Expected<U>): PromiseLike<void>;
693
694 /**
695 * Expect a promise to be rejected with a value matched to the expected.
696 * @param expected - Error constructor the object that was thrown needs to be an instance of. If not provided, Error will be used.
697 * @param message - The message that should be set on the thrown Error.
698 */
699 toBeRejectedWithError(expected?: new (...args: any[]) => Error, message?: string | RegExp): PromiseLike<void>;
700
701 /**
702 * Expect a promise to be rejected with a value matched to the expected.
703 * @param message - The message that should be set on the thrown Error.
704 */
705 toBeRejectedWithError(message?: string | RegExp): PromiseLike<void>;
706
707 /**
708 * Add some context for an expect.
709 * @param message - Additional context to show when the matcher fails.
710 */
711 withContext(message: string): AsyncMatchers<T, U>;
712
713 /**
714 * Invert the matcher following this expect.
715 */
716 not: AsyncMatchers<T, U>;
717 }
718
719 interface Reporter {
720 reportRunnerStarting(runner: Runner): void;
721 reportRunnerResults(runner: Runner): void;
722 reportSuiteResults(suite: Suite): void;
723 reportSpecStarting(spec: Spec): void;
724 reportSpecResults(spec: Spec): void;
725 log(str: string): void;
726 }
727
728 interface MultiReporter extends Reporter {
729 addReporter(reporter: Reporter): void;
730 }
731
732 interface SuiteInfo {
733 totalSpecsDefined: number;
734 }
735
736 interface CustomReportExpectation {
737 matcherName: string;
738 message: string;
739 passed: boolean;
740 stack: string;
741 }
742
743 interface FailedExpectation extends CustomReportExpectation {
744 actual: string;
745 expected: string;
746 }
747
748 interface PassedExpectation extends CustomReportExpectation {
749 }
750
751 interface CustomReporterResult {
752 description: string;
753 failedExpectations?: FailedExpectation[];
754 fullName: string;
755 id: string;
756 passedExpectations?: PassedExpectation[];
757 pendingReason?: string;
758 status?: string;
759 }
760
761 interface RunDetails {
762 failedExpectations: ExpectationResult[];
763 order: Order;
764 }
765
766 interface CustomReporter {
767 jasmineStarted?(suiteInfo: SuiteInfo): void;
768 suiteStarted?(result: CustomReporterResult): void;
769 specStarted?(result: CustomReporterResult): void;
770 specDone?(result: CustomReporterResult): void;
771 suiteDone?(result: CustomReporterResult): void;
772 jasmineDone?(runDetails: RunDetails): void;
773 }
774
775 interface Runner {
776 new (env: Env): any;
777
778 execute(): void;
779 beforeEach(beforeEachFunction: SpecFunction): void;
780 afterEach(afterEachFunction: SpecFunction): void;
781 beforeAll(beforeAllFunction: SpecFunction): void;
782 afterAll(afterAllFunction: SpecFunction): void;
783 finishCallback(): void;
784 addSuite(suite: Suite): void;
785 add(block: Block): void;
786 specs(): Spec[];
787 suites(): Suite[];
788 topLevelSuites(): Suite[];
789 results(): NestedResults;
790 }
791
792 type SpecFunction = (spec?: Spec) => void;
793
794 interface SuiteOrSpec {
795 id: number;
796 env: Env;
797 description: string;
798 queue: Queue;
799 }
800
801 interface Spec extends SuiteOrSpec {
802 new (env: Env, suite: Suite, description: string): any;
803
804 suite: Suite;
805
806 afterCallbacks: SpecFunction[];
807 spies_: Spy[];
808
809 results_: NestedResults;
810 matchersClass: Matchers<any>;
811
812 getFullName(): string;
813 results(): NestedResults;
814 log(arguments: any): any;
815 runs(func: SpecFunction): Spec;
816 addToQueue(block: Block): void;
817 addMatcherResult(result: Result): void;
818 getResult(): any;
819 expect(actual: any): any;
820 waits(timeout: number): Spec;
821 waitsFor(latchFunction: SpecFunction, timeoutMessage?: string, timeout?: number): Spec;
822 fail(e?: any): void;
823 getMatchersClass_(): Matchers<any>;
824 addMatchers(matchersPrototype: CustomMatcherFactories): void;
825 finishCallback(): void;
826 finish(onComplete?: () => void): void;
827 after(doAfter: SpecFunction): void;
828 execute(onComplete?: () => void, enabled?: boolean): any;
829 addBeforesAndAftersToQueue(): void;
830 explodes(): void;
831 spyOn(obj: any, methodName: string, ignoreMethodDoesntExist: boolean): Spy;
832 spyOnProperty(object: any, property: string, accessType?: 'get' | 'set'): Spy;
833 spyOnAllFunctions(object: any): Spy;
834
835 removeAllSpies(): void;
836 throwOnExpectationFailure: boolean;
837 }
838
839 interface XSpec {
840 id: number;
841 runs(): void;
842 }
843
844 interface Suite extends SuiteOrSpec {
845 new (env: Env, description: string, specDefinitions: () => void, parentSuite: Suite): any;
846
847 parentSuite: Suite;
848
849 getFullName(): string;
850 finish(onComplete?: () => void): void;
851 beforeEach(beforeEachFunction: SpecFunction): void;
852 afterEach(afterEachFunction: SpecFunction): void;
853 beforeAll(beforeAllFunction: SpecFunction): void;
854 afterAll(afterAllFunction: SpecFunction): void;
855 results(): NestedResults;
856 add(suiteOrSpec: SuiteOrSpec): void;
857 specs(): Spec[];
858 suites(): Suite[];
859 children(): any[];
860 execute(onComplete?: () => void): void;
861 }
862
863 interface XSuite {
864 execute(): void;
865 }
866
867 interface Spy {
868 (...params: any[]): any;
869
870 and: SpyAnd;
871 calls: Calls;
872 withArgs(...args: any[]): Spy;
873 }
874
875 type SpyObj<T> = T & {
876 [K in keyof T]: T[K] extends Function ? T[K] & Spy : T[K];
877 };
878
879 interface SpyAnd {
880 identity: string;
881
882 /** 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. */
883 callThrough(): Spy;
884 /** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */
885 returnValue(val: any): Spy;
886 /** 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. */
887 returnValues(...values: any[]): Spy;
888 /** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */
889 callFake(fn: Function): Spy;
890 /** Tell the spy to return a promise resolving to the specified value when invoked. */
891 resolveTo(val?: any): Spy;
892 /** Tell the spy to return a promise rejecting with the specified value when invoked. */
893 rejectWith(val?: any): Spy;
894 /** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */
895 throwError(msg: string|Error): Spy;
896 /** When a calling strategy is used for a spy, the original stubbing behavior can be returned at any time with and.stub. */
897 stub(): Spy;
898 }
899
900 interface Calls {
901 /** 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. */
902 any(): boolean;
903 /** By chaining the spy with calls.count(), will return the number of times the spy was called */
904 count(): number;
905 /** By chaining the spy with calls.argsFor(), will return the arguments passed to call number index */
906 argsFor(index: number): any[];
907 /** By chaining the spy with calls.allArgs(), will return the arguments to all calls */
908 allArgs(): any[];
909 /** By chaining the spy with calls.all(), will return the context (the this) and arguments passed all calls */
910 all(): CallInfo[];
911 /** By chaining the spy with calls.mostRecent(), will return the context (the this) and arguments for the most recent call */
912 mostRecent(): CallInfo;
913 /** By chaining the spy with calls.first(), will return the context (the this) and arguments for the first call */
914 first(): CallInfo;
915 /** By chaining the spy with calls.reset(), will clears all tracking for a spy */
916 reset(): void;
917 /** Set this spy to do a shallow clone of arguments passed to each invocation. */
918 saveArgumentsByValue(): void;
919 }
920
921 interface CallInfo {
922 /** The context (the this) for the call */
923 object: any;
924 /** All arguments passed to the call */
925 args: any[];
926 /** The return value of the call */
927 returnValue: any;
928 }
929
930 interface Util {
931 inherit(childClass: Function, parentClass: Function): any;
932 formatException(e: any): any;
933 htmlEscape(str: string): string;
934 argsToArray(args: any): any;
935 extend(destination: any, source: any): any;
936 }
937
938 interface JsApiReporter extends Reporter {
939 started: boolean;
940 finished: boolean;
941 result: any;
942 messages: any;
943 runDetails: RunDetails;
944
945 new (): any;
946
947 suites(): Suite[];
948 summarize_(suiteOrSpec: SuiteOrSpec): any;
949 results(): any;
950 resultsForSpec(specId: any): any;
951 log(str: any): any;
952 resultsForSpecs(specIds: any): any;
953 summarizeResult_(result: any): any;
954 }
955
956 interface Jasmine {
957 Spec: Spec;
958 clock: Clock;
959 util: Util;
960 }
961
962 var HtmlReporter: HtmlReporter;
963 var HtmlSpecFilter: HtmlSpecFilter;
964
965 /**
966 * Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
967 */
968 var DEFAULT_TIMEOUT_INTERVAL: number;
969
970 /**
971 * Maximum number of array elements to display when pretty printing objects.
972 * This will also limit the number of keys and values displayed for an object.
973 * Elements past this number will be ellipised.
974 */
975 var MAX_PRETTY_PRINT_ARRAY_LENGTH: number;
976
977 /**
978 * Maximum number of charasters to display when pretty printing objects.
979 * Characters past this number will be ellipised.
980 */
981 var MAX_PRETTY_PRINT_CHARS: number;
982
983 /**
984 * Maximum object depth the pretty printer will print to.
985 * Set this to a lower value to speed up pretty printing if you have large objects.
986 */
987 var MAX_PRETTY_PRINT_DEPTH: number;
988}
989
990declare module "jasmine" {
991 class jasmine {
992 constructor(options: any);
993 jasmine: jasmine.Jasmine;
994 addMatchers(matchers: jasmine.CustomMatcherFactories): void;
995 addReporter(reporter: jasmine.Reporter): void;
996 addSpecFile(filePath: string): void;
997 addSpecFiles(files: string[]): void;
998 configureDefaultReporter(options: any, ...args: any[]): void;
999 execute(files?: string[], filterString?: string): any;
1000 exitCodeCompletion(passed: any): void;
1001 loadConfig(config: any): void;
1002 loadConfigFile(configFilePath: any): void;
1003 loadHelpers(): void;
1004 loadSpecs(): void;
1005 onComplete(onCompleteCallback: (passed: boolean) => void): void;
1006 provideFallbackReporter(reporter: jasmine.Reporter): void;
1007 randomizeTests(value?: any): boolean;
1008 seed(value: any): void;
1009 showColors(value: any): void;
1010 stopSpecOnExpectationFailure(value: any): void;
1011 static ConsoleReporter(): any;
1012 env: jasmine.Env;
1013 reportersCount: number;
1014 completionReporter: jasmine.CustomReporter;
1015 reporter: jasmine.CustomReporter;
1016 coreVersion(): string;
1017 showingColors: boolean;
1018 projectBaseDir: string;
1019 printDeprecation(): void;
1020 specFiles: string[];
1021 helperFiles: string[];
1022 }
1023 export = jasmine;
1024}