1 | export interface Observable {
|
2 | subscribe(observer: (value: {}) => void): void;
|
3 | }
|
4 |
|
5 | export type Test = (t: TestContext) => Promise<void> | Iterator<any> | Observable | void;
|
6 | export type ContextualTest = (t: ContextualTestContext) => Promise<void> | Iterator<any> | Observable | void;
|
7 | export type SerialTest = (t: TestContext) => void;
|
8 | export type ContextualSerialTest = (t: ContextualTestContext) => void;
|
9 | export type CallbackTest = (t: CallbackTestContext) => void;
|
10 | export type ContextualCallbackTest = (t: ContextualCallbackTestContext) => void;
|
11 |
|
12 | export interface Runner {
|
13 | (name: string, run: Test): void;
|
14 | (run: Test): void;
|
15 | skip: Runner;
|
16 | cb: CallbackRunner;
|
17 | }
|
18 | export interface ContextualRunner {
|
19 | (name: string, run: ContextualTest): void;
|
20 | (run: ContextualTest): void;
|
21 | skip: ContextualRunner;
|
22 | cb: ContextualCallbackRunner;
|
23 | }
|
24 | export interface SerialRunner {
|
25 | (name: string, run: SerialTest): void;
|
26 | (run: SerialTest): void;
|
27 | skip: SerialRunner;
|
28 | }
|
29 | export interface ContextualSerialRunner {
|
30 | (name: string, run: ContextualSerialTest): void;
|
31 | (run: ContextualSerialTest): void;
|
32 | skip: ContextualSerialRunner;
|
33 | }
|
34 | export interface CallbackRunner {
|
35 | (name: string, run: CallbackTest): void;
|
36 | (run: CallbackTest): void;
|
37 | skip: CallbackRunner;
|
38 | }
|
39 | export interface ContextualCallbackRunner {
|
40 | (name: string, run: ContextualCallbackTest): void;
|
41 | (run: ContextualCallbackTest): void;
|
42 | skip: ContextualCallbackRunner;
|
43 | }
|
44 |
|
45 | export function test(name: string, run: ContextualTest): void;
|
46 | export function test(run: ContextualTest): void;
|
47 | export namespace test {
|
48 | export const before: Runner;
|
49 | export const after: Runner;
|
50 | export const beforeEach: ContextualRunner;
|
51 | export const afterEach: ContextualRunner;
|
52 |
|
53 | export const skip: typeof test;
|
54 | export const only: typeof test;
|
55 |
|
56 | export function serial(name: string, run: ContextualSerialTest): void;
|
57 | export function serial(run: ContextualSerialTest): void;
|
58 | export function cb(name: string, run: ContextualCallbackTest): void;
|
59 | export function cb(run: ContextualCallbackTest): void;
|
60 | }
|
61 | export namespace test.serial {
|
62 | export const before: SerialRunner;
|
63 | export const after: SerialRunner;
|
64 | export const beforeEach: ContextualSerialRunner;
|
65 | export const afterEach: ContextualSerialRunner;
|
66 |
|
67 | export const skip: typeof test.serial;
|
68 | export const only: typeof test.serial;
|
69 | }
|
70 | export namespace test.cb {
|
71 | export const before: CallbackRunner;
|
72 | export const after: CallbackRunner;
|
73 | export const beforeEach: ContextualCallbackRunner;
|
74 | export const afterEach: ContextualCallbackRunner;
|
75 |
|
76 | export const skip: typeof test.cb;
|
77 | export const only: typeof test.cb;
|
78 | }
|
79 | export default test;
|
80 |
|
81 | export type ErrorValidator
|
82 | = (new (...args: any[]) => any)
|
83 | | RegExp
|
84 | | string
|
85 | | ((error: any) => boolean);
|
86 |
|
87 | export interface AssertContext {
|
88 | /**
|
89 | * Passing assertion.
|
90 | */
|
91 | pass(message?: string): void;
|
92 | /**
|
93 | * Failing assertion.
|
94 | */
|
95 | fail(message?: string): void;
|
96 | /**
|
97 | * Assert that value is truthy.
|
98 | */
|
99 | ok(value: any, message?: string): void;
|
100 | /**
|
101 | * Assert that value is falsy.
|
102 | */
|
103 | notOk(value: any, message?: string): void;
|
104 | /**
|
105 | * Assert that value is true.
|
106 | */
|
107 | true(value: boolean, message?: string): void;
|
108 | /**
|
109 | * Assert that value is false.
|
110 | */
|
111 | false(value: boolean, message?: string): void;
|
112 | /**
|
113 | * Assert that value is equal to expected.
|
114 | */
|
115 | is<U>(value: U, expected: U, message?: string): void;
|
116 | /**
|
117 | * Assert that value is not equal to expected.
|
118 | */
|
119 | not<U>(value: U, expected: U, message?: string): void;
|
120 | /**
|
121 | * Assert that value is deep equal to expected.
|
122 | */
|
123 | same<U>(value: U, expected: U, message?: string): void;
|
124 | /**
|
125 | * Assert that value is not deep equal to expected.
|
126 | */
|
127 | notSame<U>(value: U, expected: U, message?: string): void;
|
128 | /**
|
129 | * Assert that function throws an error or promise rejects.
|
130 | * @param error Can be a constructor, regex, error message or validation function.
|
131 | */
|
132 | throws(value: (() => void) | Promise<{}>, error?: ErrorValidator, message?: string);
|
133 | /**
|
134 | * Assert that function doesn't throw an error or promise resolves.
|
135 | */
|
136 | notThrows(value: (() => void) | Promise<{}>, message?: string);
|
137 | /**
|
138 | * Assert that contents matches regex.
|
139 | */
|
140 | regex(contents: string, regex: RegExp, message?: string): void;
|
141 | /**
|
142 | * Assert that error is falsy.
|
143 | */
|
144 | ifError(error: any, message?: string): void;
|
145 | }
|
146 | export interface TestContext extends AssertContext {
|
147 | /**
|
148 | * Plan how many assertion there are in the test.
|
149 | * The test will fail if the actual assertion count doesn't match planned assertions.
|
150 | */
|
151 | plan(count: number): void;
|
152 |
|
153 | skip: AssertContext;
|
154 | }
|
155 | export interface CallbackTestContext extends TestContext {
|
156 | /**
|
157 | * End the test.
|
158 | */
|
159 | end(): void;
|
160 | }
|
161 | export interface ContextualTestContext extends TestContext {
|
162 | context: any;
|
163 | }
|
164 | export interface ContextualCallbackTestContext extends CallbackTestContext {
|
165 | context: any;
|
166 | }
|
167 |
|
\ | No newline at end of file |