|
| 1 | +export default test; |
| 2 | + |
| 3 | +export type ErrorValidator |
| 4 | + = (new (...args: any[]) => any) |
| 5 | + | RegExp |
| 6 | + | string |
| 7 | + | ((error: any) => boolean); |
| 8 | + |
| 9 | +export interface Observable { |
| 10 | + subscribe(observer: (value: {}) => void): void; |
| 11 | +} |
| 12 | + |
| 13 | +export type Test = (t: TestContext) => PromiseLike<void> | Iterator<any> | Observable | void; |
| 14 | +export type ContextualTest = (t: ContextualTestContext) => PromiseLike<void> | Iterator<any> | Observable | void; |
| 15 | +export type CallbackTest = (t: CallbackTestContext) => void; |
| 16 | +export type ContextualCallbackTest = (t: ContextualCallbackTestContext) => void; |
| 17 | + |
| 18 | +export interface AssertContext { |
| 19 | + /** |
| 20 | + * Passing assertion. |
| 21 | + */ |
| 22 | + pass(message?: string): void; |
| 23 | + /** |
| 24 | + * Failing assertion. |
| 25 | + */ |
| 26 | + fail(message?: string): void; |
| 27 | + /** |
| 28 | + * Assert that value is truthy. |
| 29 | + */ |
| 30 | + truthy(value: any, message?: string): void; |
| 31 | + /** |
| 32 | + * Assert that value is falsy. |
| 33 | + */ |
| 34 | + falsy(value: any, message?: string): void; |
| 35 | + /** |
| 36 | + * DEPRECATED, use `truthy`. Assert that value is truthy. |
| 37 | + */ |
| 38 | + ok(value: any, message?: string): void; |
| 39 | + /** |
| 40 | + * DEPRECATED, use `falsy`. Assert that value is falsy. |
| 41 | + */ |
| 42 | + notOk(value: any, message?: string): void; |
| 43 | + /** |
| 44 | + * Assert that value is true. |
| 45 | + */ |
| 46 | + true(value: boolean, message?: string): void; |
| 47 | + /** |
| 48 | + * Assert that value is false. |
| 49 | + */ |
| 50 | + false(value: boolean, message?: string): void; |
| 51 | + /** |
| 52 | + * Assert that value is equal to expected. |
| 53 | + */ |
| 54 | + is<U>(value: U, expected: U, message?: string): void; |
| 55 | + /** |
| 56 | + * Assert that value is not equal to expected. |
| 57 | + */ |
| 58 | + not<U>(value: U, expected: U, message?: string): void; |
| 59 | + /** |
| 60 | + * Assert that value is deep equal to expected. |
| 61 | + */ |
| 62 | + deepEqual<U>(value: U, expected: U, message?: string): void; |
| 63 | + /** |
| 64 | + * Assert that value is not deep equal to expected. |
| 65 | + */ |
| 66 | + notDeepEqual<U>(value: U, expected: U, message?: string): void; |
| 67 | + /** |
| 68 | + * Assert that function throws an error or promise rejects. |
| 69 | + * DEPRECATED, use `deepEqual`. Assert that value is deep equal to expected. |
| 70 | + * @param error Can be a constructor, regex, error message or validation function. |
| 71 | + */ |
| 72 | + same<U>(value: U, expected: U, message?: string): void; |
| 73 | + /** |
| 74 | + * DEPRECATED use `notDeepEqual`. Assert that value is not deep equal to expected. |
| 75 | + */ |
| 76 | + notSame<U>(value: U, expected: U, message?: string): void; |
| 77 | + /** |
| 78 | + * Assert that function throws an error or promise rejects. |
| 79 | + * @param error Can be a constructor, regex, error message or validation function. |
| 80 | + */ |
| 81 | + throws(value: PromiseLike<any>, error?: ErrorValidator, message?: string): Promise<any>; |
| 82 | + throws(value: () => void, error?: ErrorValidator, message?: string): any; |
| 83 | + /** |
| 84 | + * Assert that function doesn't throw an error or promise resolves. |
| 85 | + */ |
| 86 | + notThrows<U>(value: PromiseLike<U>, message?: string): Promise<U>; |
| 87 | + notThrows(value: () => void, message?: string): void; |
| 88 | + /** |
| 89 | + * Assert that contents matches regex. |
| 90 | + */ |
| 91 | + regex(contents: string, regex: RegExp, message?: string): void; |
| 92 | + /** |
| 93 | + * Assert that contents does not match regex. |
| 94 | + */ |
| 95 | + notRegex(contents, regex, message?: string): void; |
| 96 | + /** |
| 97 | + * Assert that error is falsy. |
| 98 | + */ |
| 99 | + ifError(error: any, message?: string): void; |
| 100 | +} |
| 101 | +export interface TestContext extends AssertContext { |
| 102 | + /** |
| 103 | + * Plan how many assertion there are in the test. |
| 104 | + * The test will fail if the actual assertion count doesn't match planned assertions. |
| 105 | + */ |
| 106 | + plan(count: number): void; |
| 107 | + |
| 108 | + skip: AssertContext; |
| 109 | +} |
| 110 | +export interface CallbackTestContext extends TestContext { |
| 111 | + /** |
| 112 | + * End the test. |
| 113 | + */ |
| 114 | + end(): void; |
| 115 | +} |
| 116 | +export interface ContextualTestContext extends TestContext { |
| 117 | + context: any; |
| 118 | +} |
| 119 | +export interface ContextualCallbackTestContext extends CallbackTestContext { |
| 120 | + context: any; |
| 121 | +} |
| 122 | + |
| 123 | +export function test(name: string, run: ContextualTest): void; |
| 124 | +export function test(run: ContextualTest): void; |
0 commit comments