UNPKG

4.25 kBTypeScriptView Raw
1// Type definitions for jasminewd2 2.0
2// Project: https://github.com/angular/jasminewd
3// Definitions by: Sammy Jelin <https://github.com/sjelin>
4// George Kalpakas <https://github.com/gkalpak>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 2.8
7
8/// <reference types="jasmine" />
9
10declare function it(expectation: string, assertion?: (done: DoneFn) => Promise<void>, timeout?: number): void;
11declare function fit(expectation: string, assertion?: (done: DoneFn) => Promise<void>, timeout?: number): void;
12declare function xit(expectation: string, assertion?: (done: DoneFn) => Promise<void>, timeout?: number): void;
13declare function beforeEach(action: (done: DoneFn) => Promise<void>, timeout?: number): void;
14declare function afterEach(action: (done: DoneFn) => Promise<void>, timeout?: number): void;
15declare function beforeAll(action: (done: DoneFn) => Promise<void>, timeout?: number): void;
16declare function afterAll(action: (done: DoneFn) => Promise<void>, timeout?: number): void;
17
18declare namespace jasmine {
19 interface Matchers<T> {
20 toBe(expected: any, expectationFailOutput?: any): Promise<void>;
21 toEqual(expected: any, expectationFailOutput?: any): Promise<void>;
22 toMatch(expected: string | RegExp | Promise<string | RegExp>, expectationFailOutput?: any): Promise<void>;
23 toBeDefined(expectationFailOutput?: any): Promise<void>;
24 toBeUndefined(expectationFailOutput?: any): Promise<void>;
25 toBeNull(expectationFailOutput?: any): Promise<void>;
26 toBeNaN(): Promise<void>;
27 toBeTruthy(expectationFailOutput?: any): Promise<void>;
28 toBeFalsy(expectationFailOutput?: any): Promise<void>;
29 toHaveBeenCalled(): Promise<void>;
30 toHaveBeenCalledWith(...params: any[]): Promise<void>;
31 toHaveBeenCalledTimes(expected: number | Promise<number>): Promise<void>;
32 toContain(expected: any, expectationFailOutput?: any): Promise<void>;
33 toBeLessThan(expected: number | Promise<number>, expectationFailOutput?: any): Promise<void>;
34 toBeLessThanOrEqual(expected: number | Promise<number>, expectationFailOutput?: any): Promise<void>;
35 toBeGreaterThan(expected: number | Promise<number>, expectationFailOutput?: any): Promise<void>;
36 toBeGreaterThanOrEqual(expected: number | Promise<number>, expectationFailOutput?: any): Promise<void>;
37 toBeCloseTo(expected: number | Promise<number>, precision?: any, expectationFailOutput?: any): Promise<void>;
38 toThrow(expected?: any): Promise<void>;
39 toThrowError(message?: string | RegExp | Promise<string | RegExp>): Promise<void>;
40 toThrowError(expected?: new (...args: any[]) => Error | Promise<new (...args: any[]) => Error>, message?: string | RegExp | Promise<string | RegExp>): Promise<void>;
41 }
42
43 interface ArrayLikeMatchers<T> extends Matchers<ArrayLike<T>> {
44 toBe(expected: Expected<ArrayLike<T>>, expectationFailOutput?: any): Promise<void>;
45 toEqual(expected: Expected<ArrayLike<T>>, expectationFailOutput?: any): Promise<void>;
46 toContain(expected: T, expectationFailOutput?: any): Promise<void>;
47 not: ArrayLikeMatchers<T>;
48 }
49
50 // Add definition to be compatible with latest jasmine v3 types.
51 // Even though library is not compatible with jasmine v3, there is no suitable way to configure that now here.
52 // See for more detail: https://github.com/microsoft/dtslint/issues/253
53 interface FunctionMatchers<Fn extends (...args: any[]) => any> extends Matchers<any> {
54 toHaveBeenCalledWith(...params: any[]): boolean;
55 toHaveBeenCalledWith(...params: any[]): Promise<void>;
56 }
57
58 function addMatchers(matchers: AsyncCustomMatcherFactories): void;
59
60 interface Spec {
61 addMatchers(matchers: AsyncCustomMatcherFactories): void;
62 }
63
64 interface AsyncCustomMatcherFactories {
65 [index: string]: AsyncCustomMatcherFactory;
66 }
67
68 interface AsyncCustomMatcherFactory {
69 (util: MatchersUtil, customEqualityTesters: CustomEqualityTester[]): AsyncCustomMatcher;
70 }
71
72 interface AsyncCustomMatcher {
73 compare<T>(actual: T, expected: T): AsyncCustomMatcherResult;
74 compare(actual: any, expected: any): AsyncCustomMatcherResult;
75 }
76
77 interface AsyncCustomMatcherResult {
78 pass: boolean | Promise<boolean>;
79 message?: string;
80 }
81}