|
| 1 | +export type ErrorConstructor = new (...args: any[]) => Error; |
| 2 | + |
| 3 | +/** Specify one or more expectations the thrown error must satisfy. */ |
| 4 | +export type ThrowsExpectation = { |
| 5 | + /** The thrown error must have a code that equals the given string or number. */ |
| 6 | + code?: string | number; |
| 7 | + |
| 8 | + /** The thrown error must be an instance of this constructor. */ |
| 9 | + instanceOf?: ErrorConstructor; |
| 10 | + |
| 11 | + /** The thrown error must be strictly equal to this value. */ |
| 12 | + is?: Error; |
| 13 | + |
| 14 | + /** The thrown error must have a message that equals the given string, or matches the regular expression. */ |
| 15 | + message?: string | RegExp; |
| 16 | + |
| 17 | + /** The thrown error must have a name that equals the given string. */ |
| 18 | + name?: string; |
| 19 | +}; |
| 20 | + |
| 21 | +export interface Assertions { |
| 22 | + /** |
| 23 | + * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean |
| 24 | + * indicating whether the assertion passed. Comes with power-assert. |
| 25 | + */ |
| 26 | + assert: AssertAssertion; |
| 27 | + |
| 28 | + /** |
| 29 | + * Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to |
| 30 | + * `expected`, returning a boolean indicating whether the assertion passed. |
| 31 | + */ |
| 32 | + deepEqual: DeepEqualAssertion; |
| 33 | + |
| 34 | + /** |
| 35 | + * Assert that `value` is like `selector`, returning a boolean indicating whether the assertion passed. |
| 36 | + */ |
| 37 | + like: LikeAssertion; |
| 38 | + |
| 39 | + /** Fail the test, always returning `false`. */ |
| 40 | + fail: FailAssertion; |
| 41 | + |
| 42 | + /** |
| 43 | + * Assert that `actual` is strictly false, returning a boolean indicating whether the assertion passed. |
| 44 | + */ |
| 45 | + false: FalseAssertion; |
| 46 | + |
| 47 | + /** |
| 48 | + * Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning a boolean |
| 49 | + * indicating whether the assertion passed. |
| 50 | + */ |
| 51 | + falsy: FalsyAssertion; |
| 52 | + |
| 53 | + /** |
| 54 | + * Assert that `actual` is [the same |
| 55 | + * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`, |
| 56 | + * returning a boolean indicating whether the assertion passed. |
| 57 | + */ |
| 58 | + is: IsAssertion; |
| 59 | + |
| 60 | + /** |
| 61 | + * Assert that `actual` is not [the same |
| 62 | + * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`, |
| 63 | + * returning a boolean indicating whether the assertion passed. |
| 64 | + */ |
| 65 | + not: NotAssertion; |
| 66 | + |
| 67 | + /** |
| 68 | + * Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to |
| 69 | + * `expected`, returning a boolean indicating whether the assertion passed. |
| 70 | + */ |
| 71 | + notDeepEqual: NotDeepEqualAssertion; |
| 72 | + |
| 73 | + /** |
| 74 | + * Assert that `string` does not match the regular expression, returning a boolean indicating whether the assertion |
| 75 | + * passed. |
| 76 | + */ |
| 77 | + notRegex: NotRegexAssertion; |
| 78 | + |
| 79 | + /** Assert that the function does not throw. */ |
| 80 | + notThrows: NotThrowsAssertion; |
| 81 | + |
| 82 | + /** Assert that the async function does not throw, or that the promise does not reject. Must be awaited. */ |
| 83 | + notThrowsAsync: NotThrowsAsyncAssertion; |
| 84 | + |
| 85 | + /** Count a passing assertion, always returning `true`. */ |
| 86 | + pass: PassAssertion; |
| 87 | + |
| 88 | + /** |
| 89 | + * Assert that `string` matches the regular expression, returning a boolean indicating whether the assertion passed. |
| 90 | + */ |
| 91 | + regex: RegexAssertion; |
| 92 | + |
| 93 | + /** |
| 94 | + * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a |
| 95 | + * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if |
| 96 | + * necessary record a new snapshot. |
| 97 | + */ |
| 98 | + snapshot: SnapshotAssertion; |
| 99 | + |
| 100 | + /** |
| 101 | + * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value. |
| 102 | + */ |
| 103 | + throws: ThrowsAssertion; |
| 104 | + |
| 105 | + /** |
| 106 | + * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error), or the promise rejects |
| 107 | + * with one. If so, returns a promise for the error value, which must be awaited. |
| 108 | + */ |
| 109 | + throwsAsync: ThrowsAsyncAssertion; |
| 110 | + |
| 111 | + /** |
| 112 | + * Assert that `actual` is strictly true, returning a boolean indicating whether the assertion passed. |
| 113 | + */ |
| 114 | + true: TrueAssertion; |
| 115 | + |
| 116 | + /** |
| 117 | + * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean |
| 118 | + * indicating whether the assertion passed. |
| 119 | + */ |
| 120 | + truthy: TruthyAssertion; |
| 121 | +} |
| 122 | + |
| 123 | +export interface AssertAssertion { |
| 124 | + /** |
| 125 | + * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean |
| 126 | + * indicating whether the assertion passed. Comes with power-assert. |
| 127 | + */ |
| 128 | + (actual: any, message?: string): boolean; |
| 129 | + |
| 130 | + /** Skip this assertion. */ |
| 131 | + skip(actual: any, message?: string): void; |
| 132 | +} |
| 133 | + |
| 134 | +export interface DeepEqualAssertion { |
| 135 | + /** |
| 136 | + * Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to |
| 137 | + * `expected`, returning a boolean indicating whether the assertion passed. |
| 138 | + */ |
| 139 | + <Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected; |
| 140 | + |
| 141 | + /** Skip this assertion. */ |
| 142 | + skip(actual: any, expected: any, message?: string): void; |
| 143 | +} |
| 144 | + |
| 145 | +export interface LikeAssertion { |
| 146 | + /** |
| 147 | + * Assert that `value` is like `selector`, returning a boolean indicating whether the assertion passed. |
| 148 | + */ |
| 149 | + <Expected extends Record<string, any>>(value: any, selector: Expected, message?: string): value is Expected; |
| 150 | + |
| 151 | + /** Skip this assertion. */ |
| 152 | + skip(value: any, selector: any, message?: string): void; |
| 153 | +} |
| 154 | + |
| 155 | +export interface FailAssertion { |
| 156 | + /** Fail the test, always returning `false`. */ |
| 157 | + (message?: string): boolean; |
| 158 | + |
| 159 | + /** Skip this assertion. */ |
| 160 | + skip(message?: string): void; |
| 161 | +} |
| 162 | + |
| 163 | +export interface FalseAssertion { |
| 164 | + /** |
| 165 | + * Assert that `actual` is strictly false, returning a boolean indicating whether the assertion passed. |
| 166 | + */ |
| 167 | + (actual: any, message?: string): actual is false; |
| 168 | + |
| 169 | + /** Skip this assertion. */ |
| 170 | + skip(actual: any, message?: string): void; |
| 171 | +} |
| 172 | + |
| 173 | +export interface FalsyAssertion { |
| 174 | + /** |
| 175 | + * Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning a boolean |
| 176 | + * indicating whether the assertion passed. |
| 177 | + */ |
| 178 | + (actual: any, message?: string): boolean; |
| 179 | + |
| 180 | + /** Skip this assertion. */ |
| 181 | + skip(actual: any, message?: string): void; |
| 182 | +} |
| 183 | + |
| 184 | +export interface IsAssertion { |
| 185 | + /** |
| 186 | + * Assert that `actual` is [the same |
| 187 | + * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`, |
| 188 | + * returning a boolean indicating whether the assertion passed. |
| 189 | + */ |
| 190 | + <Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected; |
| 191 | + |
| 192 | + /** Skip this assertion. */ |
| 193 | + skip(actual: any, expected: any, message?: string): void; |
| 194 | +} |
| 195 | + |
| 196 | +export interface NotAssertion { |
| 197 | + /** |
| 198 | + * Assert that `actual` is not [the same |
| 199 | + * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`, |
| 200 | + * returning a boolean indicating whether the assertion passed. |
| 201 | + */ |
| 202 | + <Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean; |
| 203 | + |
| 204 | + /** Skip this assertion. */ |
| 205 | + skip(actual: any, expected: any, message?: string): void; |
| 206 | +} |
| 207 | + |
| 208 | +export interface NotDeepEqualAssertion { |
| 209 | + /** |
| 210 | + * Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to |
| 211 | + * `expected`, returning a boolean indicating whether the assertion passed. |
| 212 | + */ |
| 213 | + <Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean; |
| 214 | + |
| 215 | + /** Skip this assertion. */ |
| 216 | + skip(actual: any, expected: any, message?: string): void; |
| 217 | +} |
| 218 | + |
| 219 | +export interface NotRegexAssertion { |
| 220 | + /** |
| 221 | + * Assert that `string` does not match the regular expression, returning a boolean indicating whether the assertion |
| 222 | + * passed. |
| 223 | + */ |
| 224 | + (string: string, regex: RegExp, message?: string): boolean; |
| 225 | + |
| 226 | + /** Skip this assertion. */ |
| 227 | + skip(string: string, regex: RegExp, message?: string): void; |
| 228 | +} |
| 229 | + |
| 230 | +export interface NotThrowsAssertion { |
| 231 | + /** Assert that the function does not throw. */ |
| 232 | + (fn: () => any, message?: string): void; |
| 233 | + |
| 234 | + /** Skip this assertion. */ |
| 235 | + skip(fn: () => any, message?: string): void; |
| 236 | +} |
| 237 | + |
| 238 | +export interface NotThrowsAsyncAssertion { |
| 239 | + /** Assert that the async function does not throw. You must await the result. */ |
| 240 | + (fn: () => PromiseLike<any>, message?: string): Promise<void>; |
| 241 | + |
| 242 | + /** Assert that the promise does not reject. You must await the result. */ |
| 243 | + (promise: PromiseLike<any>, message?: string): Promise<void>; // eslint-disable-line @typescript-eslint/unified-signatures |
| 244 | + |
| 245 | + /** Skip this assertion. */ |
| 246 | + skip(nonThrower: any, message?: string): void; |
| 247 | +} |
| 248 | + |
| 249 | +export interface PassAssertion { |
| 250 | + /** Count a passing assertion, always returning `true`. */ |
| 251 | + (message?: string): boolean; |
| 252 | + |
| 253 | + /** Skip this assertion. */ |
| 254 | + skip(message?: string): void; |
| 255 | +} |
| 256 | + |
| 257 | +export interface RegexAssertion { |
| 258 | + /** |
| 259 | + * Assert that `string` matches the regular expression, returning a boolean indicating whether the assertion passed. |
| 260 | + */ |
| 261 | + (string: string, regex: RegExp, message?: string): boolean; |
| 262 | + |
| 263 | + /** Skip this assertion. */ |
| 264 | + skip(string: string, regex: RegExp, message?: string): void; |
| 265 | +} |
| 266 | + |
| 267 | +export interface SnapshotAssertion { |
| 268 | + /** |
| 269 | + * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a |
| 270 | + * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if |
| 271 | + * necessary record a new snapshot. |
| 272 | + */ |
| 273 | + (expected: any, message?: string): void; |
| 274 | + |
| 275 | + /** Skip this assertion. */ |
| 276 | + skip(expected: any, message?: string): void; |
| 277 | +} |
| 278 | + |
| 279 | +export interface ThrowsAssertion { |
| 280 | + /** |
| 281 | + * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value. |
| 282 | + * The error must satisfy all expectations. |
| 283 | + */ |
| 284 | + <ThrownError extends Error>(fn: () => any, expectations?: ThrowsExpectation | null, message?: string): ThrownError; |
| 285 | + |
| 286 | + /** Skip this assertion. */ |
| 287 | + skip(fn: () => any, expectations?: any, message?: string): void; |
| 288 | +} |
| 289 | + |
| 290 | +export interface ThrowsAsyncAssertion { |
| 291 | + /** |
| 292 | + * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error |
| 293 | + * value. You must await the result. |
| 294 | + */ |
| 295 | + <ThrownError extends Error>(fn: () => PromiseLike<any>, expectations?: null, message?: string): Promise<ThrownError>; |
| 296 | + |
| 297 | + /** |
| 298 | + * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error |
| 299 | + * value. You must await the result. The error must satisfy all expectations. |
| 300 | + */ |
| 301 | + <ThrownError extends Error>(fn: () => PromiseLike<any>, expectations: ThrowsExpectation, message?: string): Promise<ThrownError>; |
| 302 | + |
| 303 | + /** |
| 304 | + * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the |
| 305 | + * rejection reason. You must await the result. |
| 306 | + */ |
| 307 | + <ThrownError extends Error>(promise: PromiseLike<any>, expectations?: null, message?: string): Promise<ThrownError>; // eslint-disable-line @typescript-eslint/unified-signatures |
| 308 | + |
| 309 | + /** |
| 310 | + * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the |
| 311 | + * rejection reason. You must await the result. The error must satisfy all expectations. |
| 312 | + */ |
| 313 | + <ThrownError extends Error>(promise: PromiseLike<any>, expectations: ThrowsExpectation, message?: string): Promise<ThrownError>; // eslint-disable-line @typescript-eslint/unified-signatures |
| 314 | + |
| 315 | + /** Skip this assertion. */ |
| 316 | + skip(thrower: any, expectations?: any, message?: string): void; |
| 317 | +} |
| 318 | + |
| 319 | +export interface TrueAssertion { |
| 320 | + /** |
| 321 | + * Assert that `actual` is strictly true, returning a boolean indicating whether the assertion passed. |
| 322 | + */ |
| 323 | + (actual: any, message?: string): actual is true; |
| 324 | + |
| 325 | + /** Skip this assertion. */ |
| 326 | + skip(actual: any, message?: string): void; |
| 327 | +} |
| 328 | + |
| 329 | +export interface TruthyAssertion { |
| 330 | + /** |
| 331 | + * Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean |
| 332 | + * indicating whether the assertion passed. |
| 333 | + */ |
| 334 | + (actual: any, message?: string): boolean; |
| 335 | + |
| 336 | + /** Skip this assertion. */ |
| 337 | + skip(actual: any, message?: string): void; |
| 338 | +} |
0 commit comments