@plugjs/expect5 0.4.1 → 0.4.3
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/dist/cli.mjs +1 -1
- package/dist/expectation/async.cjs +73 -0
- package/dist/expectation/async.cjs.map +6 -0
- package/dist/expectation/async.d.ts +54 -0
- package/dist/expectation/async.mjs +46 -0
- package/dist/expectation/async.mjs.map +6 -0
- package/dist/expectation/basic.cjs +155 -183
- package/dist/expectation/basic.cjs.map +1 -1
- package/dist/expectation/basic.d.ts +90 -47
- package/dist/expectation/basic.mjs +142 -163
- package/dist/expectation/basic.mjs.map +1 -1
- package/dist/expectation/diff.cjs +7 -7
- package/dist/expectation/diff.cjs.map +1 -1
- package/dist/expectation/diff.mjs +7 -7
- package/dist/expectation/diff.mjs.map +1 -1
- package/dist/expectation/expect.cjs +94 -108
- package/dist/expectation/expect.cjs.map +2 -2
- package/dist/expectation/expect.d.ts +103 -130
- package/dist/expectation/expect.mjs +131 -137
- package/dist/expectation/expect.mjs.map +2 -2
- package/dist/expectation/include.cjs +50 -61
- package/dist/expectation/include.cjs.map +1 -1
- package/dist/expectation/include.d.ts +19 -10
- package/dist/expectation/include.mjs +53 -57
- package/dist/expectation/include.mjs.map +1 -1
- package/dist/expectation/throwing.cjs +27 -27
- package/dist/expectation/throwing.cjs.map +1 -1
- package/dist/expectation/throwing.d.ts +36 -8
- package/dist/expectation/throwing.mjs +26 -26
- package/dist/expectation/throwing.mjs.map +1 -1
- package/dist/expectation/trivial.cjs +96 -0
- package/dist/expectation/trivial.cjs.map +6 -0
- package/dist/expectation/trivial.d.ts +13 -0
- package/dist/expectation/trivial.mjs +61 -0
- package/dist/expectation/trivial.mjs.map +6 -0
- package/dist/expectation/types.cjs +9 -12
- package/dist/expectation/types.cjs.map +1 -1
- package/dist/expectation/types.d.ts +52 -10
- package/dist/expectation/types.mjs +8 -10
- package/dist/expectation/types.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/expectation/async.ts +151 -0
- package/src/expectation/basic.ts +356 -156
- package/src/expectation/diff.ts +8 -9
- package/src/expectation/expect.ts +239 -268
- package/src/expectation/include.ts +93 -59
- package/src/expectation/throwing.ts +102 -41
- package/src/expectation/trivial.ts +107 -0
- package/src/expectation/types.ts +82 -25
- package/src/index.ts +2 -0
- package/dist/expectation/void.cjs +0 -111
- package/dist/expectation/void.cjs.map +0 -6
- package/dist/expectation/void.d.ts +0 -39
- package/dist/expectation/void.mjs +0 -77
- package/dist/expectation/void.mjs.map +0 -6
- package/src/expectation/void.ts +0 -80
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/expectation/types.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0FO,SAAS,OAAO,OAA0B;AAC/C,MAAI,UAAU;AAAM,WAAO;AAG3B,QAAM,OAAO,OAAO;AACpB,UAAQ,MAAM;AAAA,IACZ,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,EACX;AAGA,MAAI,MAAM,QAAQ,KAAK;AAAG,WAAO;AAEjC,MAAI,iBAAiB;AAAS,WAAO;AACrC,MAAI,OAAQ,MAAc,MAAM,MAAM;AAAY,WAAO;AAEzD,MAAI,iBAAiB;AAAQ,WAAO;AACpC,MAAI,iBAAiB;AAAQ,WAAO;AACpC,MAAI,iBAAiB;AAAK,WAAO;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ACH,aAAO,MAAM;AAAA,IAEf,KAAK;AAAA,IACL,KAAK;AACH,aAAO,OAAO;AAAA,IAEhB,KAAK;AAAA,IACL,KAAK;AACH,aAAO,IAAI;AAAA,IAEb;AACE,aAAO,oBAAoB;AAAA,EAC/B;AACF;AAMO,IAAM,gBAAgB,OAAO,IAAI,0CAA0C;AAE3E,SAAS,UAAU,MAA6B;AACrD,SAAO,QAAQ,KAAK,aAAa,MAAM;AACzC;AAMO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C;AAAA;AAAA,EAyBA,YACI,SACA,SACA,sBACA,qBACF;AACA,UAAM,OAAO,OAAO,yBAAyB,WAAW,uBAAuB;AAC/E,UAAM,WACJ,OAAO,yBAAyB,YAAY,uBAC5C,OAAO,wBAAwB,YAAY,sBAC3C,QAAQ;AAEV,UAAM,EAAE,MAAM,IAAI;AAClB,UAAM,MAAM,WAAW,SAAS;AAGhC,QAAI,WAAW,eAAe,KAAK;AACnC,QAAI,QAAQ,QAAQ;AAClB,YAAM,aAAoB,CAAC;AAE3B,aAAO,QAAQ,QAAQ;AACrB,mBAAW,KAAK,IAAI,eAAe,QAAQ,OAAO,IAAI,IAAI;AAC1D,kBAAU,QAAQ,OAAO;AAAA,MAC3B;AAEA,iBAAW,WAAW,QAAQ,EAAE,KAAK,EAAE;AAGvC,YAAM,OAAO,OAAO,QAAQ,UAAU,WAClC,oBAAoB,QAAQ,KAAe;AAAA;AAAA,QAC3C,eAAe,QAAQ,KAAK;AAAA;AAGhC,iBAAW,YAAY,eAAe,SAAS,eAAe,KAAK;AAAA,IACrE;AAEA,UAAM,YAAY,WAAW,OAAO,SAAS;AAE7C,QAAI;AAAM,WAAK,OAAO;AAAA,EACxB;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Diff } from './diff';
|
|
3
|
-
import type { Expectations,
|
|
3
|
+
import type { Expectations, Matchers, ExpectationFunctions } from './expect';
|
|
4
4
|
/** A type identifying any constructor */
|
|
5
5
|
export type Constructor<T = any> = new (...args: any[]) => T;
|
|
6
6
|
/** A type identifying any function */
|
|
@@ -11,10 +11,6 @@ export type NonArrayObject<T = any> = {
|
|
|
11
11
|
[b: symbol]: T;
|
|
12
12
|
[c: number]: never;
|
|
13
13
|
};
|
|
14
|
-
/** A type identifying the parameter of `string.match(...)` */
|
|
15
|
-
export type StringMatcher = string | RegExp | {
|
|
16
|
-
[Symbol.match](string: string): RegExpMatchArray | null;
|
|
17
|
-
};
|
|
18
14
|
/** Mappings for our _expanded_ {@link typeOf} implementation */
|
|
19
15
|
export type TypeMappings = {
|
|
20
16
|
bigint: bigint;
|
|
@@ -35,12 +31,41 @@ export type TypeMappings = {
|
|
|
35
31
|
};
|
|
36
32
|
/** Values returned by our own _expanded_ `{@link typeOf}` */
|
|
37
33
|
export type TypeName = keyof TypeMappings;
|
|
34
|
+
/** Join the asserted type of an {@link Expectations} with another type */
|
|
35
|
+
export type JoinExpectations<E, T2> = E extends Expectations<infer T1> ? Expectations<T1 & T2> : Expectations<T2>;
|
|
36
|
+
/** An assertion function, for sub-expectations and value introspection */
|
|
37
|
+
export type AssertionFunction<T = unknown> = (assert: Expectations<T>) => void | Expectations;
|
|
38
|
+
/** Get the type asserted by an {@link AssertionFunction} */
|
|
39
|
+
export type AssertedType<F extends AssertionFunction<any>, R = ReturnType<F>> = R extends Expectations<infer T> ? T : unknown;
|
|
40
|
+
/** Internal context used by expectations functions to operate */
|
|
41
|
+
export interface ExpectationsContext<T = unknown> {
|
|
42
|
+
/** The value being expected */
|
|
43
|
+
readonly value: T;
|
|
44
|
+
/** Whether this is a negative or positive expectation */
|
|
45
|
+
readonly negative: boolean;
|
|
46
|
+
/** The optional parent of this instance, when constructed for a property */
|
|
47
|
+
readonly parent?: ExpectationsParent;
|
|
48
|
+
/** The current _positive_ {@link Expectations} for the value */
|
|
49
|
+
readonly expects: Expectations<T>;
|
|
50
|
+
/**
|
|
51
|
+
* If _negative_, the _negative_ {@link ExpectationFunctions} for the value,
|
|
52
|
+
* otherwise the _positive_ ones (basically, follow the `not` of `expect`).
|
|
53
|
+
*/
|
|
54
|
+
readonly negated: ExpectationFunctions<T>;
|
|
55
|
+
/** Create an {@link Expectation} instance for the specified value */
|
|
56
|
+
forValue<V>(value: V): Expectations<V>;
|
|
57
|
+
/** Create an {@link Expectation} instance for a property of this value */
|
|
58
|
+
forProperty(prop: string | number | symbol): Expectations;
|
|
59
|
+
}
|
|
60
|
+
/** Parent expectations context (for properties) */
|
|
61
|
+
export interface ExpectationsParent {
|
|
62
|
+
context: ExpectationsContext;
|
|
63
|
+
prop: string | number | symbol;
|
|
64
|
+
}
|
|
38
65
|
/** Expanded `typeof` implementation returning some extra types */
|
|
39
66
|
export declare function typeOf(value: unknown): TypeName;
|
|
40
|
-
/** Determines if the specified `value` is of the specified _expanded_ `type` */
|
|
41
|
-
export declare function isType<T extends keyof TypeMappings>(context: Expectations, type: T): context is Expectations<TypeMappings[T]>;
|
|
42
67
|
/** Asserts that the specified `value` is of the specified _expanded_ `type` */
|
|
43
|
-
export declare function
|
|
68
|
+
export declare function assertContextType<T extends keyof TypeMappings>(context: ExpectationsContext, type: T): asserts context is ExpectationsContext<TypeMappings[T]>;
|
|
44
69
|
/** Stringify the type of an object (its constructor name) */
|
|
45
70
|
export declare function stringifyObjectType(value: object): string;
|
|
46
71
|
/** Stringify a constructor */
|
|
@@ -50,8 +75,25 @@ export declare function stringifyValue(value: unknown): string;
|
|
|
50
75
|
/** Add the `a`/`an`/... prefix to the type name */
|
|
51
76
|
export declare function prefixType(type: TypeName): string;
|
|
52
77
|
export declare const matcherMarker: unique symbol;
|
|
53
|
-
export declare function isMatcher(what: any): what is
|
|
78
|
+
export declare function isMatcher(what: any): what is Matchers;
|
|
54
79
|
export declare class ExpectationError extends Error {
|
|
55
80
|
diff?: Diff | undefined;
|
|
56
|
-
|
|
81
|
+
/** Create an {@link ExpectationError} from a context and details message */
|
|
82
|
+
constructor(context: ExpectationsContext, details: string);
|
|
83
|
+
/**
|
|
84
|
+
* Create an {@link ExpectationError} from a context and details message,
|
|
85
|
+
* including an optional {@link Diff}
|
|
86
|
+
*/
|
|
87
|
+
constructor(context: ExpectationsContext, details: string, diff?: Diff);
|
|
88
|
+
/**
|
|
89
|
+
* Create an {@link ExpectationError} from a context and details message,
|
|
90
|
+
* optionally forcing _negation_ to be as specified.
|
|
91
|
+
*/
|
|
92
|
+
constructor(context: ExpectationsContext, details: string, forcedNegative?: boolean);
|
|
93
|
+
/**
|
|
94
|
+
* Create an {@link ExpectationError} from a context and details message,
|
|
95
|
+
* including an optional {@link Diff} and forcing _negation_ to be as
|
|
96
|
+
* specified.
|
|
97
|
+
*/
|
|
98
|
+
constructor(context: ExpectationsContext, details: string, diff?: Diff, forcedNegative?: boolean);
|
|
57
99
|
}
|
|
@@ -29,14 +29,10 @@ function typeOf(value) {
|
|
|
29
29
|
return "set";
|
|
30
30
|
return "object";
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
function assertType(context, type) {
|
|
36
|
-
const { value } = context;
|
|
37
|
-
if (typeOf(value) === type)
|
|
32
|
+
function assertContextType(context, type) {
|
|
33
|
+
if (typeOf(context.value) === type)
|
|
38
34
|
return;
|
|
39
|
-
throw new ExpectationError(context,
|
|
35
|
+
throw new ExpectationError(context, `to be ${prefixType(type)}`, false);
|
|
40
36
|
}
|
|
41
37
|
function constructorName(value) {
|
|
42
38
|
return Object.getPrototypeOf(value)?.constructor?.name;
|
|
@@ -141,7 +137,10 @@ function isMatcher(what) {
|
|
|
141
137
|
}
|
|
142
138
|
var ExpectationError = class extends Error {
|
|
143
139
|
diff;
|
|
144
|
-
|
|
140
|
+
/* Overloaded constructor implementation */
|
|
141
|
+
constructor(context, details, diffOrForcedNegative, maybeForcedNegative) {
|
|
142
|
+
const diff = typeof diffOrForcedNegative === "object" ? diffOrForcedNegative : null;
|
|
143
|
+
const negative = typeof diffOrForcedNegative === "boolean" ? diffOrForcedNegative : typeof maybeForcedNegative === "boolean" ? maybeForcedNegative : context.negative;
|
|
145
144
|
const { value } = context;
|
|
146
145
|
const not = negative ? " not" : "";
|
|
147
146
|
let preamble = stringifyValue(value);
|
|
@@ -165,9 +164,8 @@ var ExpectationError = class extends Error {
|
|
|
165
164
|
};
|
|
166
165
|
export {
|
|
167
166
|
ExpectationError,
|
|
168
|
-
|
|
167
|
+
assertContextType,
|
|
169
168
|
isMatcher,
|
|
170
|
-
isType,
|
|
171
169
|
matcherMarker,
|
|
172
170
|
prefixType,
|
|
173
171
|
stringifyConstructor,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/expectation/types.ts"],
|
|
4
|
-
"mappings": ";
|
|
4
|
+
"mappings": ";AA0FO,SAAS,OAAO,OAA0B;AAC/C,MAAI,UAAU;AAAM,WAAO;AAG3B,QAAM,OAAO,OAAO;AACpB,UAAQ,MAAM;AAAA,IACZ,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,EACX;AAGA,MAAI,MAAM,QAAQ,KAAK;AAAG,WAAO;AAEjC,MAAI,iBAAiB;AAAS,WAAO;AACrC,MAAI,OAAQ,MAAc,MAAM,MAAM;AAAY,WAAO;AAEzD,MAAI,iBAAiB;AAAQ,WAAO;AACpC,MAAI,iBAAiB;AAAQ,WAAO;AACpC,MAAI,iBAAiB;AAAK,WAAO;AACjC,MAAI,iBAAiB;AAAK,WAAO;AAGjC,SAAO;AACT;AAGO,SAAS,kBACZ,SACA,MACuD;AACzD,MAAI,OAAO,QAAQ,KAAK,MAAM;AAAM;AAEpC,QAAM,IAAI,iBAAiB,SAAS,SAAS,WAAW,IAAI,KAAK,KAAK;AACxE;AAOA,SAAS,gBAAgB,O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AAuB;AAAA,
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA+B;AAC/B,mBAA+B;AAQ/B,mBAKO;AACP,wBAAqB;AACrB,oBAAuB;AAAA,IAuCvB,4BAAe,YAAQ,6BAAe,YAAW,QAAQ,GAAG,MAAM;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ForkOptions } from '@plugjs/plug/fork';
|
|
|
2
2
|
export { it, fit, xit, describe, fdescribe, xdescribe, afterAll, afterEach, xafterAll, xafterEach, beforeAll, beforeEach, xbeforeAll, xbeforeEach, } from './execution/setup';
|
|
3
3
|
export { skip } from './execution/executable';
|
|
4
4
|
export { expect } from './expectation/expect';
|
|
5
|
+
export type { Expectations } from './expectation/expect';
|
|
5
6
|
/** Options to construct our {@link Jasmine} plug. */
|
|
6
7
|
export interface TestOptions extends ForkOptions {
|
|
7
8
|
/** Report up to the specified amount of failures (default: `+Infinity`) */
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"mappings": ";AAAA,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAQ/B;AAAA,EACE;AAAA,EAAI;AAAA,EAAK;AAAA,EACT;AAAA,EAAU;AAAA,EAAW;AAAA,EACrB;AAAA,EAAU;AAAA,EAAW;AAAA,EAAW;AAAA,EAChC;AAAA,EAAW;AAAA,EAAY;AAAA,EAAY;AAAA,OAC9B;AACP,SAAS,YAAY;AACrB,SAAS,cAAc;
|
|
4
|
+
"mappings": ";AAAA,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAQ/B;AAAA,EACE;AAAA,EAAI;AAAA,EAAK;AAAA,EACT;AAAA,EAAU;AAAA,EAAW;AAAA,EACrB;AAAA,EAAU;AAAA,EAAW;AAAA,EAAW;AAAA,EAChC;AAAA,EAAW;AAAA,EAAY;AAAA,EAAY;AAAA,OAC9B;AACP,SAAS,YAAY;AACrB,SAAS,cAAc;AAuCvB,eAAe,QAAQ,eAAe,iBAAW,QAAQ,GAAG,MAAM;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plugjs/expect5",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"chai": "^4.3.7"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@plugjs/plug": "0.4.
|
|
50
|
+
"@plugjs/plug": "0.4.3"
|
|
51
51
|
},
|
|
52
52
|
"files": [
|
|
53
53
|
"*.md",
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ExpectationError } from './types'
|
|
2
|
+
|
|
3
|
+
import type { Expectations } from './expect'
|
|
4
|
+
import type {
|
|
5
|
+
AssertedType,
|
|
6
|
+
AssertionFunction,
|
|
7
|
+
Constructor,
|
|
8
|
+
ExpectationsContext,
|
|
9
|
+
} from './types'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A {@link Promise} for an {@link Expectations} instance expecting a
|
|
13
|
+
* _then-able_ {@link PromiseLike}.
|
|
14
|
+
*
|
|
15
|
+
* Long story short: the {@link toBeResolved}, {@link toBeRejectedWithError} and
|
|
16
|
+
* {@link toBeRejected} expectations are asynchronous, henceforth they return
|
|
17
|
+
* the first {@link Promise} to an {@link Expectations} instance. They also
|
|
18
|
+
* ensure that the value being expected is a _then-able_ {@link PromiseLike}.
|
|
19
|
+
*/
|
|
20
|
+
type ExpectationsPromise<E, T2 = unknown> =
|
|
21
|
+
unknown extends T2 ?
|
|
22
|
+
E extends Expectations<infer T1> ?
|
|
23
|
+
Promise<Expectations<PromiseLike<Awaited<T1>>>> :
|
|
24
|
+
Promise<Expectations<PromiseLike<unknown>>> :
|
|
25
|
+
Promise<Expectations<PromiseLike<T2>>>
|
|
26
|
+
|
|
27
|
+
/* === TO BE RESOLVED ======================================================= */
|
|
28
|
+
|
|
29
|
+
/** Expects the value to be a _resolved_ {@link PromiseLike}. */
|
|
30
|
+
function toBeResolved<T>(this: T): ExpectationsPromise<T>
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Expects the value to be a _resolved_ {@link Promise}, and asserts the
|
|
34
|
+
* resolved result with the specified callback.
|
|
35
|
+
*/
|
|
36
|
+
function toBeResolved<T, A extends AssertionFunction>(
|
|
37
|
+
this: T,
|
|
38
|
+
assert: A,
|
|
39
|
+
): ExpectationsPromise<T, AssertedType<A>>
|
|
40
|
+
|
|
41
|
+
/* Overloaded function implementation */
|
|
42
|
+
function toBeResolved(
|
|
43
|
+
this: ExpectationsContext,
|
|
44
|
+
assert?: (resultExpectations: Expectations) => void,
|
|
45
|
+
): Promise<Expectations> {
|
|
46
|
+
void assert
|
|
47
|
+
return Promise.resolve()
|
|
48
|
+
.then(() => {
|
|
49
|
+
this.expects.toHaveProperty('then', (a) => a.toBeA('function'))
|
|
50
|
+
return Promise.allSettled([ Promise.resolve(this.value) ])
|
|
51
|
+
})
|
|
52
|
+
.then(([ settlement ]) => {
|
|
53
|
+
if (settlement.status === 'fulfilled') {
|
|
54
|
+
if (this.negative) throw new ExpectationError(this, 'to be resolved')
|
|
55
|
+
if (assert) assert(this.forValue(settlement.value))
|
|
56
|
+
} else if (! this.negative) {
|
|
57
|
+
throw new ExpectationError(this, 'to be resolved')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this.expects
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* === TO BE REJECTED ======================================================= */
|
|
65
|
+
|
|
66
|
+
/** Expect the value to be a _rejected_ {@link Promise}. */
|
|
67
|
+
function toBeRejected<T>(this: T): ExpectationsPromise<T>
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Expect the value to be a _rejected_ {@link Promise}, and asserts the
|
|
71
|
+
* rejection reason with the specified callback.
|
|
72
|
+
*/
|
|
73
|
+
function toBeRejected<T>(this: T, assert: AssertionFunction): ExpectationsPromise<T>
|
|
74
|
+
|
|
75
|
+
/* Overloaded function implementation */
|
|
76
|
+
function toBeRejected(
|
|
77
|
+
this: ExpectationsContext,
|
|
78
|
+
assert?: AssertionFunction,
|
|
79
|
+
): Promise<Expectations> {
|
|
80
|
+
return Promise.resolve()
|
|
81
|
+
.then(() => {
|
|
82
|
+
this.expects.toHaveProperty('then', (a) => a.toBeA('function'))
|
|
83
|
+
return Promise.allSettled([ Promise.resolve(this.value) ])
|
|
84
|
+
})
|
|
85
|
+
.then(([ settlement ]) => {
|
|
86
|
+
if (settlement.status === 'rejected') {
|
|
87
|
+
if (this.negative) throw new ExpectationError(this, 'to be rejected')
|
|
88
|
+
if (assert) assert(this.forValue(settlement.reason))
|
|
89
|
+
} else if (! this.negative) {
|
|
90
|
+
throw new ExpectationError(this, 'to be rejected')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return this.expects
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* === TO BE REJECTED WITH ERROR ============================================ */
|
|
98
|
+
|
|
99
|
+
/** Expect the value to be a {@link Promise} _rejected_ by an {@link Error}. */
|
|
100
|
+
function toBeRejectedWithError<T>(this: T, ): ExpectationsPromise<T>
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
104
|
+
* with the specified _message_.
|
|
105
|
+
*/
|
|
106
|
+
function toBeRejectedWithError<T>(this: T, message: string): ExpectationsPromise<T>
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
110
|
+
* with its _message_ matching the specified {@link RegExp}.
|
|
111
|
+
*/
|
|
112
|
+
function toBeRejectedWithError<T>(this: T, message: RegExp): ExpectationsPromise<T>
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
116
|
+
* of the specified _type_.
|
|
117
|
+
*/
|
|
118
|
+
function toBeRejectedWithError<T>(this: T, constructor: Constructor<Error>): ExpectationsPromise<T>
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
122
|
+
* of the specified _type_ and with the specified _message_.
|
|
123
|
+
*/
|
|
124
|
+
function toBeRejectedWithError<T>(this: T, constructor: Constructor<Error>, message: string): ExpectationsPromise<T>
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
128
|
+
* of the specified _type_ and with the specified _message_.
|
|
129
|
+
*/
|
|
130
|
+
function toBeRejectedWithError<T>(this: T, constructor: Constructor<Error>, message: RegExp): ExpectationsPromise<T>
|
|
131
|
+
|
|
132
|
+
/* Overloaded function implementation */
|
|
133
|
+
function toBeRejectedWithError(
|
|
134
|
+
this: ExpectationsContext,
|
|
135
|
+
...args:
|
|
136
|
+
| []
|
|
137
|
+
| [ string ]
|
|
138
|
+
| [ RegExp ]
|
|
139
|
+
| [ Constructor<Error> ]
|
|
140
|
+
| [ Constructor<Error>, string ]
|
|
141
|
+
| [ Constructor<Error>, RegExp ]
|
|
142
|
+
): Promise<Expectations> {
|
|
143
|
+
return this.negated.toBeRejected((assert) =>
|
|
144
|
+
// @ts-ignore // can't reconcile the types with overloads...
|
|
145
|
+
assert.toBeError(...args))
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* === EXPORTS ============================================================== */
|
|
149
|
+
|
|
150
|
+
/* coverage ignore next */
|
|
151
|
+
export { toBeResolved, toBeRejected, toBeRejectedWithError }
|