UNPKG

7.94 kBTypeScriptView Raw
1// Generated by typings
2// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/mocha/mocha.d.ts
3// Type definitions for mocha 2.2.5
4// Project: http://mochajs.org/
5// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, otiai10 <https://github.com/otiai10>, jt000 <https://github.com/jt000>, Vadim Macagon <https://github.com/enlight>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
8interface MochaSetupOptions {
9 //milliseconds to wait before considering a test slow
10 slow?: number;
11
12 // timeout in milliseconds
13 timeout?: number;
14
15 // ui name "bdd", "tdd", "exports" etc
16 ui?: string;
17
18 //array of accepted globals
19 globals?: any[];
20
21 // reporter instance (function or string), defaults to `mocha.reporters.Spec`
22 reporter?: any;
23
24 // bail on the first test failure
25 bail?: boolean;
26
27 // ignore global leaks
28 ignoreLeaks?: boolean;
29
30 // grep string or regexp to filter tests with
31 grep?: any;
32}
33
34interface MochaDone {
35 (error?: Error): void;
36}
37
38declare var mocha: Mocha;
39declare var describe: Mocha.IContextDefinition;
40declare var xdescribe: Mocha.IContextDefinition;
41// alias for `describe`
42declare var context: Mocha.IContextDefinition;
43// alias for `describe`
44declare var suite: Mocha.IContextDefinition;
45declare var it: Mocha.ITestDefinition;
46declare var xit: Mocha.ITestDefinition;
47// alias for `it`
48declare var test: Mocha.ITestDefinition;
49
50declare function before(action: () => void): void;
51
52declare function before(action: (done: MochaDone) => void): void;
53
54declare function before(description: string, action: () => void): void;
55
56declare function before(description: string, action: (done: MochaDone) => void): void;
57
58declare function setup(action: () => void): void;
59
60declare function setup(action: (done: MochaDone) => void): void;
61
62declare function after(action: () => void): void;
63
64declare function after(action: (done: MochaDone) => void): void;
65
66declare function after(description: string, action: () => void): void;
67
68declare function after(description: string, action: (done: MochaDone) => void): void;
69
70declare function teardown(action: () => void): void;
71
72declare function teardown(action: (done: MochaDone) => void): void;
73
74declare function beforeEach(action: () => void): void;
75
76declare function beforeEach(action: (done: MochaDone) => void): void;
77
78declare function beforeEach(description: string, action: () => void): void;
79
80declare function beforeEach(description: string, action: (done: MochaDone) => void): void;
81
82declare function suiteSetup(action: () => void): void;
83
84declare function suiteSetup(action: (done: MochaDone) => void): void;
85
86declare function afterEach(action: () => void): void;
87
88declare function afterEach(action: (done: MochaDone) => void): void;
89
90declare function afterEach(description: string, action: () => void): void;
91
92declare function afterEach(description: string, action: (done: MochaDone) => void): void;
93
94declare function suiteTeardown(action: () => void): void;
95
96declare function suiteTeardown(action: (done: MochaDone) => void): void;
97
98declare class Mocha {
99 constructor(options?: {
100 grep?: RegExp;
101 ui?: string;
102 reporter?: string;
103 timeout?: number;
104 bail?: boolean;
105 });
106
107 /** Setup mocha with the given options. */
108 setup(options: MochaSetupOptions): Mocha;
109 bail(value?: boolean): Mocha;
110 addFile(file: string): Mocha;
111 /** Sets reporter by name, defaults to "spec". */
112 reporter(name: string): Mocha;
113 /** Sets reporter constructor, defaults to mocha.reporters.Spec. */
114 reporter(reporter: (runner: Mocha.IRunner, options: any) => any): Mocha;
115 ui(value: string): Mocha;
116 grep(value: string): Mocha;
117 grep(value: RegExp): Mocha;
118 invert(): Mocha;
119 ignoreLeaks(value: boolean): Mocha;
120 checkLeaks(): Mocha;
121 /**
122 * Function to allow assertion libraries to throw errors directly into mocha.
123 * This is useful when running tests in a browser because window.onerror will
124 * only receive the 'message' attribute of the Error.
125 */
126 throwError(error: Error): void;
127 /** Enables growl support. */
128 growl(): Mocha;
129 globals(value: string): Mocha;
130 globals(values: string[]): Mocha;
131 useColors(value: boolean): Mocha;
132 useInlineDiffs(value: boolean): Mocha;
133 timeout(value: number): Mocha;
134 slow(value: number): Mocha;
135 enableTimeouts(value: boolean): Mocha;
136 asyncOnly(value: boolean): Mocha;
137 noHighlighting(value: boolean): Mocha;
138 /** Runs tests and invokes `onComplete()` when finished. */
139 run(onComplete?: (failures: number) => void): Mocha.IRunner;
140}
141
142// merge the Mocha class declaration with a module
143declare namespace Mocha {
144 /** Partial interface for Mocha's `Runnable` class. */
145 interface IRunnable {
146 title: string;
147 fn: Function;
148 async: boolean;
149 sync: boolean;
150 timedOut: boolean;
151 }
152
153 /** Partial interface for Mocha's `Suite` class. */
154 interface ISuite {
155 parent: ISuite;
156 title: string;
157
158 fullTitle(): string;
159 }
160
161 /** Partial interface for Mocha's `Test` class. */
162 interface ITest extends IRunnable {
163 parent: ISuite;
164 pending: boolean;
165
166 fullTitle(): string;
167 }
168
169 /** Partial interface for Mocha's `Runner` class. */
170 interface IRunner {}
171
172 interface IContextDefinition {
173 (description: string, spec: () => void): ISuite;
174 only(description: string, spec: () => void): ISuite;
175 skip(description: string, spec: () => void): void;
176 timeout(ms: number): void;
177 }
178
179 interface ITestDefinition {
180 (expectation: string, assertion?: () => void): ITest;
181 (expectation: string, assertion?: (done: MochaDone) => void): ITest;
182 only(expectation: string, assertion?: () => void): ITest;
183 only(expectation: string, assertion?: (done: MochaDone) => void): ITest;
184 skip(expectation: string, assertion?: () => void): void;
185 skip(expectation: string, assertion?: (done: MochaDone) => void): void;
186 timeout(ms: number): void;
187 }
188
189 export module reporters {
190 export class Base {
191 stats: {
192 suites: number;
193 tests: number;
194 passes: number;
195 pending: number;
196 failures: number;
197 };
198
199 constructor(runner: IRunner);
200 }
201
202 export class Doc extends Base {}
203 export class Dot extends Base {}
204 export class HTML extends Base {}
205 export class HTMLCov extends Base {}
206 export class JSON extends Base {}
207 export class JSONCov extends Base {}
208 export class JSONStream extends Base {}
209 export class Landing extends Base {}
210 export class List extends Base {}
211 export class Markdown extends Base {}
212 export class Min extends Base {}
213 export class Nyan extends Base {}
214 export class Progress extends Base {
215 /**
216 * @param options.open String used to indicate the start of the progress bar.
217 * @param options.complete String used to indicate a complete test on the progress bar.
218 * @param options.incomplete String used to indicate an incomplete test on the progress bar.
219 * @param options.close String used to indicate the end of the progress bar.
220 */
221 constructor(runner: IRunner, options?: {
222 open?: string;
223 complete?: string;
224 incomplete?: string;
225 close?: string;
226 });
227 }
228 export class Spec extends Base {}
229 export class TAP extends Base {}
230 export class XUnit extends Base {
231 constructor(runner: IRunner, options?: any);
232 }
233 }
234}
235
236declare module "mocha" {
237 export = Mocha;
238}
\No newline at end of file