Matteo Scandolo | 5461a7c | 2017-08-08 13:05:24 -0700 | [diff] [blame^] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | fc4b37b | 2017-02-02 12:18:47 -0800 | [diff] [blame] | 19 | // Generated by typings |
| 20 | // Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/dc9dabe74a5be62613b17a3605309783a12ff28a/jasmine/jasmine.d.ts |
| 21 | declare function describe(description: string, specDefinitions: () => void): void; |
| 22 | declare function fdescribe(description: string, specDefinitions: () => void): void; |
| 23 | declare function xdescribe(description: string, specDefinitions: () => void): void; |
| 24 | |
| 25 | declare function it(expectation: string, assertion?: () => void, timeout?: number): void; |
| 26 | declare function it(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; |
| 27 | declare function fit(expectation: string, assertion?: () => void, timeout?: number): void; |
| 28 | declare function fit(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; |
| 29 | declare function xit(expectation: string, assertion?: () => void, timeout?: number): void; |
| 30 | declare function xit(expectation: string, assertion?: (done: () => void) => void, timeout?: number): void; |
| 31 | |
| 32 | /** If you call the function pending anywhere in the spec body, no matter the expectations, the spec will be marked pending. */ |
| 33 | declare function pending(reason?: string): void; |
| 34 | |
| 35 | declare function beforeEach(action: () => void, timeout?: number): void; |
| 36 | declare function beforeEach(action: (done: () => void) => void, timeout?: number): void; |
| 37 | declare function afterEach(action: () => void, timeout?: number): void; |
| 38 | declare function afterEach(action: (done: () => void) => void, timeout?: number): void; |
| 39 | |
| 40 | declare function beforeAll(action: () => void, timeout?: number): void; |
| 41 | declare function beforeAll(action: (done: () => void) => void, timeout?: number): void; |
| 42 | declare function afterAll(action: () => void, timeout?: number): void; |
| 43 | declare function afterAll(action: (done: () => void) => void, timeout?: number): void; |
| 44 | |
| 45 | declare function expect(spy: Function): jasmine.Matchers; |
| 46 | declare function expect(actual: any): jasmine.Matchers; |
| 47 | |
| 48 | declare function fail(e?: any): void; |
| 49 | |
| 50 | declare function spyOn(object: any, method: string): jasmine.Spy; |
| 51 | |
| 52 | declare function runs(asyncMethod: Function): void; |
| 53 | declare function waitsFor(latchMethod: () => boolean, failureMessage?: string, timeout?: number): void; |
| 54 | declare function waits(timeout?: number): void; |
| 55 | |
| 56 | declare module jasmine { |
| 57 | |
| 58 | var clock: () => Clock; |
| 59 | |
| 60 | function any(aclass: any): Any; |
| 61 | function anything(): Any; |
| 62 | function arrayContaining(sample: any[]): ArrayContaining; |
| 63 | function objectContaining(sample: any): ObjectContaining; |
| 64 | function createSpy(name: string, originalFn?: Function): Spy; |
| 65 | function createSpyObj(baseName: string, methodNames: any[]): any; |
| 66 | function createSpyObj<T>(baseName: string, methodNames: any[]): T; |
| 67 | function pp(value: any): string; |
| 68 | function getEnv(): Env; |
| 69 | function addCustomEqualityTester(equalityTester: CustomEqualityTester): void; |
| 70 | function addMatchers(matchers: CustomMatcherFactories): void; |
| 71 | function stringMatching(str: string): Any; |
| 72 | function stringMatching(str: RegExp): Any; |
| 73 | |
| 74 | interface Any { |
| 75 | |
| 76 | new (expectedClass: any): any; |
| 77 | |
| 78 | jasmineMatches(other: any): boolean; |
| 79 | jasmineToString(): string; |
| 80 | } |
| 81 | |
| 82 | // taken from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains() |
| 83 | interface ArrayLike<T> { |
| 84 | length: number; |
| 85 | [n: number]: T; |
| 86 | } |
| 87 | |
| 88 | interface ArrayContaining { |
| 89 | new (sample: any[]): any; |
| 90 | |
| 91 | asymmetricMatch(other: any): boolean; |
| 92 | jasmineToString(): string; |
| 93 | } |
| 94 | |
| 95 | interface ObjectContaining { |
| 96 | new (sample: any): any; |
| 97 | |
| 98 | jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean; |
| 99 | jasmineToString(): string; |
| 100 | } |
| 101 | |
| 102 | interface Block { |
| 103 | |
| 104 | new (env: Env, func: SpecFunction, spec: Spec): any; |
| 105 | |
| 106 | execute(onComplete: () => void): void; |
| 107 | } |
| 108 | |
| 109 | interface WaitsBlock extends Block { |
| 110 | new (env: Env, timeout: number, spec: Spec): any; |
| 111 | } |
| 112 | |
| 113 | interface WaitsForBlock extends Block { |
| 114 | new (env: Env, timeout: number, latchFunction: SpecFunction, message: string, spec: Spec): any; |
| 115 | } |
| 116 | |
| 117 | interface Clock { |
| 118 | install(): void; |
| 119 | uninstall(): void; |
| 120 | /** 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. */ |
| 121 | tick(ms: number): void; |
| 122 | mockDate(date?: Date): void; |
| 123 | } |
| 124 | |
| 125 | interface CustomEqualityTester { |
| 126 | (first: any, second: any): boolean; |
| 127 | } |
| 128 | |
| 129 | interface CustomMatcher { |
| 130 | compare<T>(actual: T, expected: T): CustomMatcherResult; |
| 131 | compare(actual: any, expected: any): CustomMatcherResult; |
| 132 | } |
| 133 | |
| 134 | interface CustomMatcherFactory { |
| 135 | (util: MatchersUtil, customEqualityTesters: Array<CustomEqualityTester>): CustomMatcher; |
| 136 | } |
| 137 | |
| 138 | interface CustomMatcherFactories { |
| 139 | [index: string]: CustomMatcherFactory; |
| 140 | } |
| 141 | |
| 142 | interface CustomMatcherResult { |
| 143 | pass: boolean; |
| 144 | message?: string; |
| 145 | } |
| 146 | |
| 147 | interface MatchersUtil { |
| 148 | equals(a: any, b: any, customTesters?: Array<CustomEqualityTester>): boolean; |
| 149 | contains<T>(haystack: ArrayLike<T> | string, needle: any, customTesters?: Array<CustomEqualityTester>): boolean; |
| 150 | buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: Array<any>): string; |
| 151 | } |
| 152 | |
| 153 | interface Env { |
| 154 | setTimeout: any; |
| 155 | clearTimeout: void; |
| 156 | setInterval: any; |
| 157 | clearInterval: void; |
| 158 | updateInterval: number; |
| 159 | |
| 160 | currentSpec: Spec; |
| 161 | |
| 162 | matchersClass: Matchers; |
| 163 | |
| 164 | version(): any; |
| 165 | versionString(): string; |
| 166 | nextSpecId(): number; |
| 167 | addReporter(reporter: Reporter): void; |
| 168 | execute(): void; |
| 169 | describe(description: string, specDefinitions: () => void): Suite; |
| 170 | // ddescribe(description: string, specDefinitions: () => void): Suite; Not a part of jasmine. Angular team adds these |
| 171 | beforeEach(beforeEachFunction: () => void): void; |
| 172 | beforeAll(beforeAllFunction: () => void): void; |
| 173 | currentRunner(): Runner; |
| 174 | afterEach(afterEachFunction: () => void): void; |
| 175 | afterAll(afterAllFunction: () => void): void; |
| 176 | xdescribe(desc: string, specDefinitions: () => void): XSuite; |
| 177 | it(description: string, func: () => void): Spec; |
| 178 | // iit(description: string, func: () => void): Spec; Not a part of jasmine. Angular team adds these |
| 179 | xit(desc: string, func: () => void): XSpec; |
| 180 | compareRegExps_(a: RegExp, b: RegExp, mismatchKeys: string[], mismatchValues: string[]): boolean; |
| 181 | compareObjects_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean; |
| 182 | equals_(a: any, b: any, mismatchKeys: string[], mismatchValues: string[]): boolean; |
| 183 | contains_(haystack: any, needle: any): boolean; |
| 184 | addCustomEqualityTester(equalityTester: CustomEqualityTester): void; |
| 185 | addMatchers(matchers: CustomMatcherFactories): void; |
| 186 | specFilter(spec: Spec): boolean; |
| 187 | } |
| 188 | |
| 189 | interface FakeTimer { |
| 190 | |
| 191 | new (): any; |
| 192 | |
| 193 | reset(): void; |
| 194 | tick(millis: number): void; |
| 195 | runFunctionsWithinRange(oldMillis: number, nowMillis: number): void; |
| 196 | scheduleFunction(timeoutKey: any, funcToCall: () => void, millis: number, recurring: boolean): void; |
| 197 | } |
| 198 | |
| 199 | interface HtmlReporter { |
| 200 | new (): any; |
| 201 | } |
| 202 | |
| 203 | interface HtmlSpecFilter { |
| 204 | new (): any; |
| 205 | } |
| 206 | |
| 207 | interface Result { |
| 208 | type: string; |
| 209 | } |
| 210 | |
| 211 | interface NestedResults extends Result { |
| 212 | description: string; |
| 213 | |
| 214 | totalCount: number; |
| 215 | passedCount: number; |
| 216 | failedCount: number; |
| 217 | |
| 218 | skipped: boolean; |
| 219 | |
| 220 | rollupCounts(result: NestedResults): void; |
| 221 | log(values: any): void; |
| 222 | getItems(): Result[]; |
| 223 | addResult(result: Result): void; |
| 224 | passed(): boolean; |
| 225 | } |
| 226 | |
| 227 | interface MessageResult extends Result { |
| 228 | values: any; |
| 229 | trace: Trace; |
| 230 | } |
| 231 | |
| 232 | interface ExpectationResult extends Result { |
| 233 | matcherName: string; |
| 234 | passed(): boolean; |
| 235 | expected: any; |
| 236 | actual: any; |
| 237 | message: string; |
| 238 | trace: Trace; |
| 239 | } |
| 240 | |
| 241 | interface Trace { |
| 242 | name: string; |
| 243 | message: string; |
| 244 | stack: any; |
| 245 | } |
| 246 | |
| 247 | interface PrettyPrinter { |
| 248 | |
| 249 | new (): any; |
| 250 | |
| 251 | format(value: any): void; |
| 252 | iterateObject(obj: any, fn: (property: string, isGetter: boolean) => void): void; |
| 253 | emitScalar(value: any): void; |
| 254 | emitString(value: string): void; |
| 255 | emitArray(array: any[]): void; |
| 256 | emitObject(obj: any): void; |
| 257 | append(value: any): void; |
| 258 | } |
| 259 | |
| 260 | interface StringPrettyPrinter extends PrettyPrinter { |
| 261 | } |
| 262 | |
| 263 | interface Queue { |
| 264 | |
| 265 | new (env: any): any; |
| 266 | |
| 267 | env: Env; |
| 268 | ensured: boolean[]; |
| 269 | blocks: Block[]; |
| 270 | running: boolean; |
| 271 | index: number; |
| 272 | offset: number; |
| 273 | abort: boolean; |
| 274 | |
| 275 | addBefore(block: Block, ensure?: boolean): void; |
| 276 | add(block: any, ensure?: boolean): void; |
| 277 | insertNext(block: any, ensure?: boolean): void; |
| 278 | start(onComplete?: () => void): void; |
| 279 | isRunning(): boolean; |
| 280 | next_(): void; |
| 281 | results(): NestedResults; |
| 282 | } |
| 283 | |
| 284 | interface Matchers { |
| 285 | |
| 286 | new (env: Env, actual: any, spec: Env, isNot?: boolean): any; |
| 287 | |
| 288 | env: Env; |
| 289 | actual: any; |
| 290 | spec: Env; |
| 291 | isNot?: boolean; |
| 292 | message(): any; |
| 293 | |
| 294 | toBe(expected: any, expectationFailOutput?: any): boolean; |
| 295 | toEqual(expected: any, expectationFailOutput?: any): boolean; |
| 296 | toMatch(expected: string | RegExp, expectationFailOutput?: any): boolean; |
| 297 | toBeDefined(expectationFailOutput?: any): boolean; |
| 298 | toBeUndefined(expectationFailOutput?: any): boolean; |
| 299 | toBeNull(expectationFailOutput?: any): boolean; |
| 300 | toBeNaN(): boolean; |
| 301 | toBeTruthy(expectationFailOutput?: any): boolean; |
| 302 | toBeFalsy(expectationFailOutput?: any): boolean; |
| 303 | toHaveBeenCalled(): boolean; |
| 304 | toHaveBeenCalledWith(...params: any[]): boolean; |
| 305 | toContain(expected: any, expectationFailOutput?: any): boolean; |
| 306 | toBeLessThan(expected: number, expectationFailOutput?: any): boolean; |
| 307 | toBeGreaterThan(expected: number, expectationFailOutput?: any): boolean; |
| 308 | toBeCloseTo(expected: number, precision: any, expectationFailOutput?: any): boolean; |
| 309 | toThrow(expected?: any): boolean; |
| 310 | toThrowError(message?: string | RegExp): boolean; |
| 311 | toThrowError(expected?: Error, message?: string | RegExp): boolean; |
| 312 | not: Matchers; |
| 313 | |
| 314 | Any: Any; |
| 315 | } |
| 316 | |
| 317 | interface Reporter { |
| 318 | reportRunnerStarting(runner: Runner): void; |
| 319 | reportRunnerResults(runner: Runner): void; |
| 320 | reportSuiteResults(suite: Suite): void; |
| 321 | reportSpecStarting(spec: Spec): void; |
| 322 | reportSpecResults(spec: Spec): void; |
| 323 | log(str: string): void; |
| 324 | } |
| 325 | |
| 326 | interface MultiReporter extends Reporter { |
| 327 | addReporter(reporter: Reporter): void; |
| 328 | } |
| 329 | |
| 330 | interface Runner { |
| 331 | |
| 332 | new (env: Env): any; |
| 333 | |
| 334 | execute(): void; |
| 335 | beforeEach(beforeEachFunction: SpecFunction): void; |
| 336 | afterEach(afterEachFunction: SpecFunction): void; |
| 337 | beforeAll(beforeAllFunction: SpecFunction): void; |
| 338 | afterAll(afterAllFunction: SpecFunction): void; |
| 339 | finishCallback(): void; |
| 340 | addSuite(suite: Suite): void; |
| 341 | add(block: Block): void; |
| 342 | specs(): Spec[]; |
| 343 | suites(): Suite[]; |
| 344 | topLevelSuites(): Suite[]; |
| 345 | results(): NestedResults; |
| 346 | } |
| 347 | |
| 348 | interface SpecFunction { |
| 349 | (spec?: Spec): void; |
| 350 | } |
| 351 | |
| 352 | interface SuiteOrSpec { |
| 353 | id: number; |
| 354 | env: Env; |
| 355 | description: string; |
| 356 | queue: Queue; |
| 357 | } |
| 358 | |
| 359 | interface Spec extends SuiteOrSpec { |
| 360 | |
| 361 | new (env: Env, suite: Suite, description: string): any; |
| 362 | |
| 363 | suite: Suite; |
| 364 | |
| 365 | afterCallbacks: SpecFunction[]; |
| 366 | spies_: Spy[]; |
| 367 | |
| 368 | results_: NestedResults; |
| 369 | matchersClass: Matchers; |
| 370 | |
| 371 | getFullName(): string; |
| 372 | results(): NestedResults; |
| 373 | log(arguments: any): any; |
| 374 | runs(func: SpecFunction): Spec; |
| 375 | addToQueue(block: Block): void; |
| 376 | addMatcherResult(result: Result): void; |
| 377 | expect(actual: any): any; |
| 378 | waits(timeout: number): Spec; |
| 379 | waitsFor(latchFunction: SpecFunction, timeoutMessage?: string, timeout?: number): Spec; |
| 380 | fail(e?: any): void; |
| 381 | getMatchersClass_(): Matchers; |
| 382 | addMatchers(matchersPrototype: CustomMatcherFactories): void; |
| 383 | finishCallback(): void; |
| 384 | finish(onComplete?: () => void): void; |
| 385 | after(doAfter: SpecFunction): void; |
| 386 | execute(onComplete?: () => void): any; |
| 387 | addBeforesAndAftersToQueue(): void; |
| 388 | explodes(): void; |
| 389 | spyOn(obj: any, methodName: string, ignoreMethodDoesntExist: boolean): Spy; |
| 390 | removeAllSpies(): void; |
| 391 | } |
| 392 | |
| 393 | interface XSpec { |
| 394 | id: number; |
| 395 | runs(): void; |
| 396 | } |
| 397 | |
| 398 | interface Suite extends SuiteOrSpec { |
| 399 | |
| 400 | new (env: Env, description: string, specDefinitions: () => void, parentSuite: Suite): any; |
| 401 | |
| 402 | parentSuite: Suite; |
| 403 | |
| 404 | getFullName(): string; |
| 405 | finish(onComplete?: () => void): void; |
| 406 | beforeEach(beforeEachFunction: SpecFunction): void; |
| 407 | afterEach(afterEachFunction: SpecFunction): void; |
| 408 | beforeAll(beforeAllFunction: SpecFunction): void; |
| 409 | afterAll(afterAllFunction: SpecFunction): void; |
| 410 | results(): NestedResults; |
| 411 | add(suiteOrSpec: SuiteOrSpec): void; |
| 412 | specs(): Spec[]; |
| 413 | suites(): Suite[]; |
| 414 | children(): any[]; |
| 415 | execute(onComplete?: () => void): void; |
| 416 | } |
| 417 | |
| 418 | interface XSuite { |
| 419 | execute(): void; |
| 420 | } |
| 421 | |
| 422 | interface Spy { |
| 423 | (...params: any[]): any; |
| 424 | |
| 425 | identity: string; |
| 426 | and: SpyAnd; |
| 427 | calls: Calls; |
| 428 | mostRecentCall: { args: any[]; }; |
| 429 | argsForCall: any[]; |
| 430 | wasCalled: boolean; |
| 431 | } |
| 432 | |
| 433 | interface SpyAnd { |
| 434 | /** 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. */ |
| 435 | callThrough(): Spy; |
| 436 | /** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */ |
| 437 | returnValue(val: any): void; |
| 438 | /** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */ |
| 439 | callFake(fn: Function): Spy; |
| 440 | /** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */ |
| 441 | throwError(msg: string): void; |
| 442 | /** When a calling strategy is used for a spy, the original stubbing behavior can be returned at any time with and.stub. */ |
| 443 | stub(): Spy; |
| 444 | } |
| 445 | |
| 446 | interface Calls { |
| 447 | /** 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. **/ |
| 448 | any(): boolean; |
| 449 | /** By chaining the spy with calls.count(), will return the number of times the spy was called **/ |
| 450 | count(): number; |
| 451 | /** By chaining the spy with calls.argsFor(), will return the arguments passed to call number index **/ |
| 452 | argsFor(index: number): any[]; |
| 453 | /** By chaining the spy with calls.allArgs(), will return the arguments to all calls **/ |
| 454 | allArgs(): any[]; |
| 455 | /** By chaining the spy with calls.all(), will return the context (the this) and arguments passed all calls **/ |
| 456 | all(): CallInfo[]; |
| 457 | /** By chaining the spy with calls.mostRecent(), will return the context (the this) and arguments for the most recent call **/ |
| 458 | mostRecent(): CallInfo; |
| 459 | /** By chaining the spy with calls.first(), will return the context (the this) and arguments for the first call **/ |
| 460 | first(): CallInfo; |
| 461 | /** By chaining the spy with calls.reset(), will clears all tracking for a spy **/ |
| 462 | reset(): void; |
| 463 | } |
| 464 | |
| 465 | interface CallInfo { |
| 466 | /** The context (the this) for the call */ |
| 467 | object: any; |
| 468 | /** All arguments passed to the call */ |
| 469 | args: any[]; |
| 470 | } |
| 471 | |
| 472 | interface Util { |
| 473 | inherit(childClass: Function, parentClass: Function): any; |
| 474 | formatException(e: any): any; |
| 475 | htmlEscape(str: string): string; |
| 476 | argsToArray(args: any): any; |
| 477 | extend(destination: any, source: any): any; |
| 478 | } |
| 479 | |
| 480 | interface JsApiReporter extends Reporter { |
| 481 | |
| 482 | started: boolean; |
| 483 | finished: boolean; |
| 484 | result: any; |
| 485 | messages: any; |
| 486 | |
| 487 | new (): any; |
| 488 | |
| 489 | suites(): Suite[]; |
| 490 | summarize_(suiteOrSpec: SuiteOrSpec): any; |
| 491 | results(): any; |
| 492 | resultsForSpec(specId: any): any; |
| 493 | log(str: any): any; |
| 494 | resultsForSpecs(specIds: any): any; |
| 495 | summarizeResult_(result: any): any; |
| 496 | } |
| 497 | |
| 498 | interface Jasmine { |
| 499 | Spec: Spec; |
| 500 | clock: Clock; |
| 501 | util: Util; |
| 502 | } |
| 503 | |
| 504 | export var HtmlReporter: HtmlReporter; |
| 505 | export var HtmlSpecFilter: HtmlSpecFilter; |
| 506 | export var DEFAULT_TIMEOUT_INTERVAL: number; |
| 507 | } |