2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 // Type definitions for Jasmine 2.2
21 // Project: http://jasmine.github.io/
22 // Definitions by: Boris Yankov <https://github.com/borisyankov/>, Theodore Brown <https://github.com/theodorejb>, David Pärsson <https://github.com/davidparsson/>
23 // Definitions: https://github.com/borisyankov/DefinitelyTyped
26 // For ddescribe / iit use : https://github.com/borisyankov/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts
28 declare function describe(description: string, specDefinitions: () => void): void;
29 declare function fdescribe(description: string, specDefinitions: () => void): void;
30 declare function xdescribe(description: string, specDefinitions: () => void): void;
32 declare function it(expectation: string, assertion?: () => void, timeout?: number): void;
33 declare function it(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void;
34 declare function fit(expectation: string, assertion?: () => void, timeout?: number): void;
35 declare function fit(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void;
36 declare function xit(expectation: string, assertion?: () => void, timeout?: number): void;
37 declare function xit(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void;
39 /** If you call the function pending anywhere in the spec body, no matter the expectations, the spec will be marked pending. */
40 declare function pending(reason?: string): void;
42 declare function beforeEach(action: () => void, timeout?: number): void;
43 declare function beforeEach(action: (done: () => void) => void, timeout?: number): void;
44 declare function afterEach(action: () => void, timeout?: number): void;
45 declare function afterEach(action: (done: () => void) => void, timeout?: number): void;
47 declare function beforeAll(action: () => void, timeout?: number): void;
48 declare function beforeAll(action: (done: () => void) => void, timeout?: number): void;
49 declare function afterAll(action: () => void, timeout?: number): void;
50 declare function afterAll(action: (done: () => void) => void, timeout?: number): void;
52 declare function expect(spy: Function): jasmine.Matchers;
53 declare function expect(actual: any): jasmine.Matchers;
55 declare function fail(e?: any): void;
57 declare function spyOn(object: any, method: string): jasmine.Spy;
59 declare function runs(asyncMethod: Function): void;
60 declare function waitsFor(latchMethod: () => boolean, failureMessage?: string, timeout?: number): void;
61 declare function waits(timeout?: number): void;
63 declare module jasmine {
65 var clock: () => Clock;
67 function any(aclass: any): Any;
68 function anything(): Any;
69 function arrayContaining(sample: any[]): ArrayContaining;
70 function objectContaining(sample: any): ObjectContaining;
71 function createSpy(name: string, originalFn?: Function): Spy;
72 function createSpyObj(baseName: string, methodNames: any[]): any;
73 function createSpyObj<T>(baseName: string, methodNames: any[]): T;
74 function pp(value: any): string;
75 function getEnv(): Env;
76 function addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
77 function addMatchers(matchers: CustomMatcherFactories): void;
78 function stringMatching(str: string): Any;
79 function stringMatching(str: RegExp): Any;
83 new (expectedClass: any): any;
85 jasmineMatches(other: any): boolean;
86 jasmineToString(): string;
89 // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains()
90 interface ArrayLike<T> {
95 interface ArrayContaining {
96 new (sample: any[]): any;
98 asymmetricMatch(other: any): boolean;
99 jasmineToString(): string;
102 interface ObjectContaining {
103 new (sample: any): any;
105 jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean;
106 jasmineToString(): string;
111 new (env: Env, func: SpecFunction, spec: Spec): any;
113 execute(onComplete: () => void): void;
116 interface WaitsBlock extends Block {
117 new (env: Env, timeout: number, spec: Spec): any;
120 interface WaitsForBlock extends Block {
121 new (env: Env, timeout: number, latchFunction: SpecFunction, message: string, spec: Spec): any;
127 /** 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. */
128 tick(ms: number): void;
129 mockDate(date?: Date): void;
132 interface CustomEqualityTester {
133 (first: any, second: any): boolean;
136 interface CustomMatcher {
137 compare<T>(actual: T, expected: T): CustomMatcherResult;
138 compare(actual: any, expected: any): CustomMatcherResult;
141 interface CustomMatcherFactory {
142 (util: MatchersUtil, customEqualityTesters: Array<CustomEqualityTester>): CustomMatcher;
145 interface CustomMatcherFactories {
146 [index: string]: CustomMatcherFactory;
149 interface CustomMatcherResult {
154 interface MatchersUtil {
155 equals(a: any, b: any, customTesters?: Array<CustomEqualityTester>): boolean;
156 contains<T>(haystack: ArrayLike<T> | string, needle: any, customTesters?: Array<CustomEqualityTester>): boolean;
157 buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: Array<any>): string;
165 updateInterval: number;
169 matchersClass: Matchers;
172 versionString(): string;
173 nextSpecId(): number;
174 addReporter(reporter: Reporter): void;
176 describe(description: string, specDefinitions: () => void): Suite;
177 // ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these
178 beforeEach(beforeEachFunction: () => void): void;
179 beforeAll(beforeAllFunction: () => void): void;
180 currentRunner(): Runner;
181 afterEach(afterEachFunction: () => void): void;
182 afterAll(afterAllFunction: () => void): void;
183 xdescribe(desc: string, specDefinitions: () => void): XSuite;
184 it(description: string, func: () => void): Spec;
185 // iit(description: string, func: () => void): Spec; Not a part of jasmine. Angular team adds these
186 xit(desc: string, func: () => void): XSpec;
187 compareRegExps_(a: RegExp, b: RegExp, mismatchKeys: string[], mismatchValues: string[]): boolean;
188 compareObjects_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean;
189 equals_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean;
190 contains_(haystack: any, needle: any): boolean;
191 addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
192 addMatchers(matchers: CustomMatcherFactories): void;
193 specFilter(spec: Spec): boolean;
196 interface FakeTimer {
201 tick(millis: number): void;
202 runFunctionsWithinRange(oldMillis: number, nowMillis: number): void;
203 scheduleFunction(timeoutKey: any, funcToCall: () => void, millis: number, recurring: boolean): void;
206 interface HtmlReporter {
210 interface HtmlSpecFilter {
218 interface NestedResults extends Result {
227 rollupCounts(result: NestedResults): void;
228 log(values: any): void;
229 getItems(): Result[];
230 addResult(result: Result): void;
234 interface MessageResult extends Result {
239 interface ExpectationResult extends Result {
254 interface PrettyPrinter {
258 format(value: any): void;
259 iterateObject(obj: any, fn: (property: string, isGetter: boolean) => void): void;
260 emitScalar(value: any): void;
261 emitString(value: string): void;
262 emitArray(array: any[]): void;
263 emitObject(obj: any): void;
264 append(value: any): void;
267 interface StringPrettyPrinter extends PrettyPrinter {
282 addBefore(block: Block, ensure?: boolean): void;
283 add(block: any, ensure?: boolean): void;
284 insertNext(block: any, ensure?: boolean): void;
285 start(onComplete?: () => void): void;
286 isRunning(): boolean;
288 results(): NestedResults;
293 new (env: Env, actual: any, spec: Env, isNot?: boolean): any;
301 toBe(expected: any, expectationFailOutput?: any): boolean;
302 toEqual(expected: any, expectationFailOutput?: any): boolean;
303 toMatch(expected: any, expectationFailOutput?: any): boolean;
304 toBeDefined(expectationFailOutput?: any): boolean;
305 toBeUndefined(expectationFailOutput?: any): boolean;
306 toBeNull(expectationFailOutput?: any): boolean;
308 toBeTruthy(expectationFailOutput?: any): boolean;
309 toBeFalsy(expectationFailOutput?: any): boolean;
310 toHaveBeenCalled(): boolean;
311 toHaveBeenCalledWith(...params: any[]): boolean;
312 toContain(expected: any, expectationFailOutput?: any): boolean;
313 toBeLessThan(expected: any, expectationFailOutput?: any): boolean;
314 toBeGreaterThan(expected: any, expectationFailOutput?: any): boolean;
315 toBeCloseTo(expected: any, precision: any, expectationFailOutput?: any): boolean;
316 toContainHtml(expected: string): boolean;
317 toContainText(expected: string): boolean;
318 toThrow(expected?: any): boolean;
319 toThrowError(expected?: any, message?: string): boolean;
326 reportRunnerStarting(runner: Runner): void;
327 reportRunnerResults(runner: Runner): void;
328 reportSuiteResults(suite: Suite): void;
329 reportSpecStarting(spec: Spec): void;
330 reportSpecResults(spec: Spec): void;
331 log(str: string): void;
334 interface MultiReporter extends Reporter {
335 addReporter(reporter: Reporter): void;
343 beforeEach(beforeEachFunction: SpecFunction): void;
344 afterEach(afterEachFunction: SpecFunction): void;
345 beforeAll(beforeAllFunction: SpecFunction): void;
346 afterAll(afterAllFunction: SpecFunction): void;
347 finishCallback(): void;
348 addSuite(suite: Suite): void;
349 add(block: Block): void;
352 topLevelSuites(): Suite[];
353 results(): NestedResults;
356 interface SpecFunction {
360 interface SuiteOrSpec {
367 interface Spec extends SuiteOrSpec {
369 new (env: Env, suite: Suite, description: string): any;
373 afterCallbacks: SpecFunction[];
376 results_: NestedResults;
377 matchersClass: Matchers;
379 getFullName(): string;
380 results(): NestedResults;
381 log(arguments: any): any;
382 runs(func: SpecFunction): Spec;
383 addToQueue(block: Block): void;
384 addMatcherResult(result: Result): void;
385 expect(actual: any): any;
386 waits(timeout: number): Spec;
387 waitsFor(latchFunction: SpecFunction, timeoutMessage?: string, timeout?: number): Spec;
389 getMatchersClass_(): Matchers;
390 addMatchers(matchersPrototype: CustomMatcherFactories): void;
391 finishCallback(): void;
392 finish(onComplete?: () => void): void;
393 after(doAfter: SpecFunction): void;
394 execute(onComplete?: () => void): any;
395 addBeforesAndAftersToQueue(): void;
397 spyOn(obj: any, methodName: string, ignoreMethodDoesntExist: boolean): Spy;
398 removeAllSpies(): void;
406 interface Suite extends SuiteOrSpec {
408 new (env: Env, description: string, specDefinitions: () => void, parentSuite: Suite): any;
412 getFullName(): string;
413 finish(onComplete?: () => void): void;
414 beforeEach(beforeEachFunction: SpecFunction): void;
415 afterEach(afterEachFunction: SpecFunction): void;
416 beforeAll(beforeAllFunction: SpecFunction): void;
417 afterAll(afterAllFunction: SpecFunction): void;
418 results(): NestedResults;
419 add(suiteOrSpec: SuiteOrSpec): void;
423 execute(onComplete?: () => void): void;
431 (...params: any[]): any;
436 mostRecentCall: { args: any[]; };
442 /** 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. */
444 /** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */
445 returnValue(val: any): void;
446 /** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */
447 callFake(fn: Function): Spy;
448 /** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */
449 throwError(msg: string): void;
450 /** When a calling strategy is used for a spy, the original stubbing behavior can be returned at any time with and.stub. */
455 /** 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. **/
457 /** By chaining the spy with calls.count(), will return the number of times the spy was called **/
459 /** By chaining the spy with calls.argsFor(), will return the arguments passed to call number index **/
460 argsFor(index: number): any[];
461 /** By chaining the spy with calls.allArgs(), will return the arguments to all calls **/
463 /** By chaining the spy with calls.all(), will return the context (the this) and arguments passed all calls **/
465 /** By chaining the spy with calls.mostRecent(), will return the context (the this) and arguments for the most recent call **/
466 mostRecent(): CallInfo;
467 /** By chaining the spy with calls.first(), will return the context (the this) and arguments for the first call **/
469 /** By chaining the spy with calls.reset(), will clears all tracking for a spy **/
474 /** The context (the this) for the call */
476 /** All arguments passed to the call */
481 inherit(childClass: Function, parentClass: Function): any;
482 formatException(e: any): any;
483 htmlEscape(str: string): string;
484 argsToArray(args: any): any;
485 extend(destination: any, source: any): any;
488 interface JsApiReporter extends Reporter {
498 summarize_(suiteOrSpec: SuiteOrSpec): any;
500 resultsForSpec(specId: any): any;
502 resultsForSpecs(specIds: any): any;
503 summarizeResult_(result: any): any;
512 export var HtmlReporter: HtmlReporter;
513 export var HtmlSpecFilter: HtmlSpecFilter;
514 export var DEFAULT_TIMEOUT_INTERVAL: number;