UNPKG

6.66 kBTypeScriptView Raw
1declare namespace Mocha {
2 export interface ITest {
3 <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;
4 }
5 export interface Test {
6 <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;
7 }
8 export interface ISuite {
9 <TFunction extends Function>(target: TFunction): TFunction | void;
10 }
11 export interface Suite {
12 <TFunction extends Function>(target: TFunction): TFunction | void;
13 }
14 // @types/mocha v5.2.4
15 interface SuiteFunction {
16 (args: any): any;
17 (): ClassDecorator;
18 (name: string): ClassDecorator;
19 (name: string, ... traits: MochaTypeScript.SuiteTrait[]): ClassDecorator;
20 (trait: MochaTypeScript.SuiteTrait, ... traits:MochaTypeScript.SuiteTrait[]): ClassDecorator;
21 }
22 interface PendingSuiteFunction {
23 (args: any): any;
24 (): ClassDecorator;
25 (name: string): ClassDecorator;
26 (name: string, ... traits: MochaTypeScript.SuiteTrait[]): ClassDecorator;
27 (trait: MochaTypeScript.SuiteTrait, ... traits:MochaTypeScript.SuiteTrait[]): ClassDecorator;
28 }
29 interface ExclusiveSuiteFunction {
30 (args: any): any;
31 (): ClassDecorator;
32 (name: string): ClassDecorator;
33 (name: string, ... traits: MochaTypeScript.SuiteTrait[]): ClassDecorator;
34 (trait: MochaTypeScript.SuiteTrait, ... traits:MochaTypeScript.SuiteTrait[]): ClassDecorator;
35 }
36 interface TestFunction {
37 (target: Object, propertyKey: string | symbol): void;
38 (name: string): PropertyDecorator;
39 (name: string, ... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
40 (... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
41 }
42 interface PendingTestFunction {
43 (target: Object, propertyKey: string | symbol): void;
44 (name: string): PropertyDecorator;
45 (name: string, ... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
46 (... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
47 }
48 interface ExclusiveTestFunction {
49 (target: Object, propertyKey: string | symbol): void;
50 (name: string): PropertyDecorator;
51 (name: string, ... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
52 (... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
53 }
54}
55
56declare namespace MochaTypeScript {
57 export interface Suite {
58 prototype: {
59 before?: (done?: MochaDone) => void;
60 after?: (done?: MochaDone) => void;
61 };
62 before?: (done?: MochaDone) => void;
63 after?: (done?: MochaDone) => void;
64 new(): any;
65 }
66 export interface SuiteTrait {
67 (this: Mocha.ISuiteCallbackContext, ctx: Mocha.ISuiteCallbackContext, ctor: Function): void;
68 }
69 export interface TestTrait {
70 (this: Mocha.ITestCallbackContext, ctx: Mocha.ITestCallbackContext, instance: Object, method: Function): void;
71 }
72
73 export interface IContextDefinition {
74 /**
75 * This is either a single trait overload `(trait: MochaTypeScript.SuiteTrait): ClassDecorator`
76 * or a class decorator overload `(target: Function): void`.
77 * Can't figure out proper typing.
78 */
79 (args: any): any;
80 (): ClassDecorator;
81 (name: string): ClassDecorator;
82 (name: string, ... traits: MochaTypeScript.SuiteTrait[]): ClassDecorator;
83 (trait: MochaTypeScript.SuiteTrait, ... traits:MochaTypeScript.SuiteTrait[]): ClassDecorator;
84
85 only(arg: any): any;
86 only(): ClassDecorator;
87 only(name: string): ClassDecorator;
88 only(name: string, ... traits: MochaTypeScript.SuiteTrait[]): ClassDecorator;
89 only(... traits:MochaTypeScript.SuiteTrait[]): ClassDecorator;
90
91 skip(arg: any): any;
92 skip(): ClassDecorator;
93 skip(name: string): ClassDecorator;
94 skip(name: string, ... traits: MochaTypeScript.SuiteTrait[]): ClassDecorator;
95 skip(... traits:MochaTypeScript.SuiteTrait[]): ClassDecorator;
96 }
97 export interface ITestDefinition {
98 (target: Object, propertyKey: string | symbol): void;
99 (name: string): PropertyDecorator;
100 (name: string, ... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
101 (... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
102
103 only(target: Object, propertyKey: string | symbol): void;
104 only(name: string): PropertyDecorator;
105 only(name: string, ... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
106 only(... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
107
108 skip(target: Object, propertyKey: string | symbol): void;
109 skip(name: string): PropertyDecorator;
110 skip(name: string, ... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
111 skip(... traits: MochaTypeScript.TestTrait[]): PropertyDecorator;
112 }
113
114 export interface TestClass<T> {
115 new(...args: any[]): T;
116 prototype: T;
117 }
118
119 export interface DependencyInjectionSystem {
120 handles<T>(cls: TestClass<T>): boolean;
121 create<T>(cls: TestClass<T>): typeof cls.prototype;
122 }
123}
124
125declare module "mocha-typescript" {
126 export const suite: Mocha.IContextDefinition & MochaTypeScript.IContextDefinition;
127 export const test: Mocha.ITestDefinition & MochaTypeScript.ITestDefinition;
128
129 export const describe: Mocha.IContextDefinition & MochaTypeScript.IContextDefinition;
130 export const it: Mocha.ITestDefinition & MochaTypeScript.ITestDefinition;
131
132 export function slow(time: number): PropertyDecorator & ClassDecorator & MochaTypeScript.SuiteTrait & MochaTypeScript.TestTrait;
133 export function timeout(time: number): PropertyDecorator & ClassDecorator & MochaTypeScript.SuiteTrait & MochaTypeScript.TestTrait;
134 export function retries(count: number): PropertyDecorator & ClassDecorator & MochaTypeScript.SuiteTrait & MochaTypeScript.TestTrait;
135
136 export function pending<TFunction extends Function>(target: Object | TFunction, propertyKey?: string | symbol): void;
137 export function only<TFunction extends Function>(target: Object, propertyKey?: string | symbol): void;
138 export function skip<TFunction extends Function>(target: Object | TFunction, propertyKey?: string | symbol): void;
139
140 export function context(target: Object, propertyKey: string | symbol): void;
141
142 export const skipOnError: MochaTypeScript.SuiteTrait;
143
144 export function registerDI(instantiator: MochaTypeScript.DependencyInjectionSystem): boolean;
145}