forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.d.ts
125 lines (107 loc) · 4.43 KB
/
jest.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Type definitions for Jest 0.9.0
// Project: http://facebook.github.io/jest/
// Definitions by: Asana <https://asana.com>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare function afterEach(fn: jest.EmptyFunction): void;
declare function beforeEach(fn: jest.EmptyFunction): void;
declare function describe(name: string, fn: jest.EmptyFunction): void;
declare var it: jest.It;
declare function pit(name: string, fn: jest.EmptyFunction): void;
declare function xdescribe(name: string, fn: jest.EmptyFunction): void;
declare function xit(name: string, fn: jest.EmptyFunction): void;
declare function expect(actual: any): jest.Matchers;
interface NodeRequire {
requireActual(moduleName: string): any;
}
declare namespace jest {
function addMatchers(matchers: CustomMatcherFactories): void;
function autoMockOff(): void;
function autoMockOn(): void;
function clearAllTimers(): void;
function currentTestPath(): string;
function disableAutomock(): void;
function fn<T>(implementation?: Function): Mock<T>;
function dontMock(moduleName: string): void;
function genMockFromModule<T>(moduleName: string): Mock<T>;
function mock(moduleName: string, factory?: Function): void;
function runAllTicks(): void;
function runAllTimers(): void;
function runOnlyPendingTimers(): void;
function setMock<T>(moduleName: string, moduleExports: T): void;
function unmock(moduleName: string): void;
interface EmptyFunction {
(): void;
}
interface Matchers {
not: Matchers;
toThrow(expected?: any): boolean;
toBe(expected: any): boolean;
toEqual(expected: any): boolean;
toBeFalsy(): boolean;
toBeTruthy(): boolean;
toBeNull(): boolean;
toBeDefined(): boolean;
toBeUndefined(): boolean;
toMatch(expected: RegExp): boolean;
toContain(expected: string): boolean;
toBeCloseTo(expected: number, delta: number): boolean;
toBeGreaterThan(expected: number): boolean;
toBeLessThan(expected: number): boolean;
toBeCalled(): boolean;
toBeCalledWith(...args: any[]): boolean;
lastCalledWith(...args: any[]): boolean;
}
interface It {
(name: string, fn: EmptyFunction): void;
only(name: string, fn: EmptyFunction): void;
}
interface Mock<T> {
new (): T;
(...args: any[]): any; // TODO please fix this line! added for TypeScript 1.1.0-1 https://github.com/DefinitelyTyped/DefinitelyTyped/pull/2932
mock: MockContext<T>;
mockClear(): void;
mockImplementation(fn: Function): Mock<T>;
mockImpl(fn: Function): Mock<T>;
mockReturnThis(): Mock<T>;
mockReturnValue(value: any): Mock<T>;
mockReturnValueOnce(value: any): Mock<T>;
}
interface MockContext<T> {
calls: any[][];
instances: T[];
}
// taken from Jasmine since addMatchers calls into the jasmine api
interface CustomMatcherFactories {
[index: string]: CustomMatcherFactory;
}
// taken from Jasmine since addMatchers calls into the jasmine api
interface CustomMatcherFactory {
(util: MatchersUtil, customEqualityTesters: Array<CustomEqualityTester>): CustomMatcher;
}
// taken from Jasmine since addMatchers calls into the jasmine api
interface MatchersUtil {
equals(a: any, b: any, customTesters?: Array<CustomEqualityTester>): boolean;
contains<T>(haystack: ArrayLike<T> | string, needle: any, customTesters?: Array<CustomEqualityTester>): boolean;
buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: Array<any>): string;
}
// taken from Jasmine since addMatchers calls into the jasmine api
interface CustomEqualityTester {
(first: any, second: any): boolean;
}
// taken from Jasmine since addMatchers calls into the jasmine api
interface CustomMatcher {
compare<T>(actual: T, expected: T): CustomMatcherResult;
compare(actual: any, expected: any): CustomMatcherResult;
}
// taken from Jasmine since addMatchers calls into the jasmine api
interface CustomMatcherResult {
pass: boolean;
message: string;
}
// taken from Jasmine which takes from TypeScript lib.core.es6.d.ts, applicable to CustomMatchers.contains()
interface ArrayLike<T> {
length: number;
[n: number]: T;
}
}