ava 5.1.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.md +5 -2
- package/types/assertions.d.cts +12 -7
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -45,11 +45,12 @@ Your `package.json` will then look like this (exact version notwithstanding):
|
|
|
45
45
|
```json
|
|
46
46
|
{
|
|
47
47
|
"name": "awesome-package",
|
|
48
|
+
"type": "module",
|
|
48
49
|
"scripts": {
|
|
49
50
|
"test": "ava"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"ava": "^
|
|
53
|
+
"ava": "^5.0.0"
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
```
|
|
@@ -72,7 +73,9 @@ Don't forget to configure the `test` script in your `package.json` as per above.
|
|
|
72
73
|
|
|
73
74
|
### Create your test file
|
|
74
75
|
|
|
75
|
-
Create a file named `test.js` in the project root directory
|
|
76
|
+
Create a file named `test.js` in the project root directory.
|
|
77
|
+
|
|
78
|
+
_Note that AVA's documentation assumes you're using ES modules._
|
|
76
79
|
|
|
77
80
|
```js
|
|
78
81
|
import test from 'ava';
|
package/types/assertions.d.cts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
export type ErrorConstructor
|
|
1
|
+
export type ErrorConstructor<ErrorType extends Error = Error> = {
|
|
2
|
+
new (...args: any[]): ErrorType;
|
|
3
|
+
readonly prototype: ErrorType;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type ThrownError<ErrorType extends ErrorConstructor | Error> = ErrorType extends ErrorConstructor ? ErrorType['prototype'] : ErrorType;
|
|
2
7
|
|
|
3
8
|
/** Specify one or more expectations the thrown error must satisfy. */
|
|
4
|
-
export type ThrowsExpectation = {
|
|
9
|
+
export type ThrowsExpectation<ErrorType extends ErrorConstructor | Error> = {
|
|
5
10
|
/** The thrown error must have a code that equals the given string or number. */
|
|
6
11
|
code?: string | number;
|
|
7
12
|
|
|
8
13
|
/** The thrown error must be an instance of this constructor. */
|
|
9
|
-
instanceOf?: ErrorConstructor;
|
|
14
|
+
instanceOf?: ErrorType extends ErrorConstructor ? ErrorType : ErrorType extends Error ? ErrorConstructor<ErrorType> : never;
|
|
10
15
|
|
|
11
16
|
/** The thrown error must be strictly equal to this value. */
|
|
12
|
-
is?:
|
|
17
|
+
is?: ErrorType extends ErrorConstructor ? ErrorType['prototype'] : ErrorType;
|
|
13
18
|
|
|
14
19
|
/** The thrown error must have a message that equals the given string, or matches the regular expression. */
|
|
15
20
|
message?: string | RegExp | ((message: string) => boolean);
|
|
@@ -293,7 +298,7 @@ export type ThrowsAssertion = {
|
|
|
293
298
|
* Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value.
|
|
294
299
|
* The error must satisfy all expectations. Returns undefined when the assertion fails.
|
|
295
300
|
*/
|
|
296
|
-
<
|
|
301
|
+
<ErrorType extends ErrorConstructor | Error>(fn: () => any, expectations?: ThrowsExpectation<ErrorType>, message?: string): ThrownError<ErrorType> | undefined;
|
|
297
302
|
|
|
298
303
|
/** Skip this assertion. */
|
|
299
304
|
skip(fn: () => any, expectations?: any, message?: string): void;
|
|
@@ -304,14 +309,14 @@ export type ThrowsAsyncAssertion = {
|
|
|
304
309
|
* Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error
|
|
305
310
|
* value. Returns undefined when the assertion fails. You must await the result. The error must satisfy all expectations.
|
|
306
311
|
*/
|
|
307
|
-
<
|
|
312
|
+
<ErrorType extends ErrorConstructor | Error>(fn: () => PromiseLike<any>, expectations?: ThrowsExpectation<ErrorType>, message?: string): Promise<ThrownError<ErrorType> | undefined>;
|
|
308
313
|
|
|
309
314
|
/**
|
|
310
315
|
* Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the
|
|
311
316
|
* rejection reason. Returns undefined when the assertion fails. You must await the result. The error must satisfy all
|
|
312
317
|
* expectations.
|
|
313
318
|
*/
|
|
314
|
-
<
|
|
319
|
+
<ErrorType extends ErrorConstructor | Error>(promise: PromiseLike<any>, expectations?: ThrowsExpectation<ErrorType>, message?: string): Promise<ThrownError<ErrorType> | undefined>;
|
|
315
320
|
|
|
316
321
|
/** Skip this assertion. */
|
|
317
322
|
skip(thrower: any, expectations?: any, message?: string): void;
|