CSIT Fix for SDC-2585
[sdc.git] / catalog-ui / src / typings / jasmine / jasmine.d.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
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
24
25
26 // For ddescribe / iit use : https://github.com/borisyankov/DefinitelyTyped/blob/master/karma-jasmine/karma-jasmine.d.ts
27
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;
31
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;
38
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;
41
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;
46
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;
51
52 declare function expect(spy: Function): jasmine.Matchers;
53 declare function expect(actual: any): jasmine.Matchers;
54
55 declare function fail(e?: any): void;
56
57 declare function spyOn(object: any, method: string): jasmine.Spy;
58
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;
62
63 declare module jasmine {
64
65     var clock: () => Clock;
66
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;
80
81     interface Any {
82
83         new (expectedClass: any): any;
84
85         jasmineMatches(other: any): boolean;
86         jasmineToString(): string;
87     }
88
89     // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains()
90     interface ArrayLike<T> {
91         length: number;
92         [n: number]: T;
93     }
94
95     interface ArrayContaining {
96         new (sample: any[]): any;
97
98         asymmetricMatch(other: any): boolean;
99         jasmineToString(): string;
100     }
101
102     interface ObjectContaining {
103         new (sample: any): any;
104
105         jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean;
106         jasmineToString(): string;
107     }
108
109     interface Block {
110
111         new (env: Env, func: SpecFunction, spec: Spec): any;
112
113         execute(onComplete: () => void): void;
114     }
115
116     interface WaitsBlock extends Block {
117         new (env: Env, timeout: number, spec: Spec): any;
118     }
119
120     interface WaitsForBlock extends Block {
121         new (env: Env, timeout: number, latchFunction: SpecFunction, message: string, spec: Spec): any;
122     }
123
124     interface Clock {
125         install(): void;
126         uninstall(): void;
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;
130     }
131
132     interface CustomEqualityTester {
133         (first: any, second: any): boolean;
134     }
135
136     interface CustomMatcher {
137         compare<T>(actual: T, expected: T): CustomMatcherResult;
138         compare(actual: any, expected: any): CustomMatcherResult;
139     }
140
141     interface CustomMatcherFactory {
142         (util: MatchersUtil, customEqualityTesters: Array<CustomEqualityTester>): CustomMatcher;
143     }
144
145     interface CustomMatcherFactories {
146         [index: string]: CustomMatcherFactory;
147     }
148
149     interface CustomMatcherResult {
150         pass: boolean;
151         message: string;
152     }
153
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;
158     }
159
160     interface Env {
161         setTimeout: any;
162         clearTimeout: void;
163         setInterval: any;
164         clearInterval: void;
165         updateInterval: number;
166
167         currentSpec: Spec;
168
169         matchersClass: Matchers;
170
171         version(): any;
172         versionString(): string;
173         nextSpecId(): number;
174         addReporter(reporter: Reporter): void;
175         execute(): 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;
194     }
195
196     interface FakeTimer {
197
198         new (): any;
199
200         reset(): void;
201         tick(millis: number): void;
202         runFunctionsWithinRange(oldMillis: number, nowMillis: number): void;
203         scheduleFunction(timeoutKey: any, funcToCall: () => void, millis: number, recurring: boolean): void;
204     }
205
206     interface HtmlReporter {
207         new (): any;
208     }
209
210     interface HtmlSpecFilter {
211         new (): any;
212     }
213
214     interface Result {
215         type: string;
216     }
217
218     interface NestedResults extends Result {
219         description: string;
220
221         totalCount: number;
222         passedCount: number;
223         failedCount: number;
224
225         skipped: boolean;
226
227         rollupCounts(result: NestedResults): void;
228         log(values: any): void;
229         getItems(): Result[];
230         addResult(result: Result): void;
231         passed(): boolean;
232     }
233
234     interface MessageResult extends Result  {
235         values: any;
236         trace: Trace;
237     }
238
239     interface ExpectationResult extends Result  {
240         matcherName: string;
241         passed(): boolean;
242         expected: any;
243         actual: any;
244         message: string;
245         trace: Trace;
246     }
247
248     interface Trace {
249         name: string;
250         message: string;
251         stack: any;
252     }
253
254     interface PrettyPrinter {
255
256         new (): any;
257
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;
265     }
266
267     interface StringPrettyPrinter extends PrettyPrinter {
268     }
269
270     interface Queue {
271
272         new (env: any): any;
273
274         env: Env;
275         ensured: boolean[];
276         blocks: Block[];
277         running: boolean;
278         index: number;
279         offset: number;
280         abort: boolean;
281
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;
287         next_(): void;
288         results(): NestedResults;
289     }
290
291     interface Matchers {
292
293         new (env: Env, actual: any, spec: Env, isNot?: boolean): any;
294
295         env: Env;
296         actual: any;
297         spec: Env;
298         isNot?: boolean;
299         message(): any;
300
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;
307         toBeNaN(): 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;
320         not: Matchers;
321
322         Any: Any;
323     }
324
325     interface Reporter {
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;
332     }
333
334     interface MultiReporter extends Reporter {
335         addReporter(reporter: Reporter): void;
336     }
337
338     interface Runner {
339
340         new (env: Env): any;
341
342         execute(): 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;
350         specs(): Spec[];
351         suites(): Suite[];
352         topLevelSuites(): Suite[];
353         results(): NestedResults;
354     }
355
356     interface SpecFunction {
357         (spec?: Spec): void;
358     }
359
360     interface SuiteOrSpec {
361         id: number;
362         env: Env;
363         description: string;
364         queue: Queue;
365     }
366
367     interface Spec extends SuiteOrSpec {
368
369         new (env: Env, suite: Suite, description: string): any;
370
371         suite: Suite;
372
373         afterCallbacks: SpecFunction[];
374         spies_: Spy[];
375
376         results_: NestedResults;
377         matchersClass: Matchers;
378
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;
388         fail(e?: any): void;
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;
396         explodes(): void;
397         spyOn(obj: any, methodName: string, ignoreMethodDoesntExist: boolean): Spy;
398         removeAllSpies(): void;
399     }
400
401     interface XSpec {
402         id: number;
403         runs(): void;
404     }
405
406     interface Suite extends SuiteOrSpec {
407
408         new (env: Env, description: string, specDefinitions: () => void, parentSuite: Suite): any;
409
410         parentSuite: Suite;
411
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;
420         specs(): Spec[];
421         suites(): Suite[];
422         children(): any[];
423         execute(onComplete?: () => void): void;
424     }
425
426     interface XSuite {
427         execute(): void;
428     }
429
430     interface Spy {
431         (...params: any[]): any;
432
433         identity: string;
434         and: SpyAnd;
435         calls: Calls;
436         mostRecentCall: { args: any[]; };
437         argsForCall: any[];
438         wasCalled: boolean;
439     }
440
441     interface SpyAnd {
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. */
443         callThrough(): Spy;
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. */
451         stub(): Spy;
452     }
453
454     interface Calls {
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. **/
456         any(): boolean;
457         /** By chaining the spy with calls.count(), will return the number of times the spy was called **/
458         count(): number;
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 **/
462         allArgs(): any[];
463         /** By chaining the spy with calls.all(), will return the context (the this) and arguments passed all calls **/
464         all(): CallInfo[];
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 **/
468         first(): CallInfo;
469         /** By chaining the spy with calls.reset(), will clears all tracking for a spy **/
470         reset(): void;
471     }
472
473     interface CallInfo {
474         /** The context (the this) for the call */
475         object: any;
476         /** All arguments passed to the call */
477         args: any[];
478     }
479
480     interface Util {
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;
486     }
487
488     interface JsApiReporter extends Reporter {
489
490         started: boolean;
491         finished: boolean;
492         result: any;
493         messages: any;
494
495         new (): any;
496
497         suites(): Suite[];
498         summarize_(suiteOrSpec: SuiteOrSpec): any;
499         results(): any;
500         resultsForSpec(specId: any): any;
501         log(str: any): any;
502         resultsForSpecs(specIds: any): any;
503         summarizeResult_(result: any): any;
504     }
505
506     interface Jasmine {
507         Spec: Spec;
508         clock: Clock;
509         util: Util;
510     }
511
512     export var HtmlReporter: HtmlReporter;
513     export var HtmlSpecFilter: HtmlSpecFilter;
514     export var DEFAULT_TIMEOUT_INTERVAL: number;
515 }