@plugjs/expect5 0.4.2 → 0.4.4
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 +360 -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
package/dist/cli.mjs
CHANGED
|
@@ -8,7 +8,7 @@ var { $blu, $und, $gry, $wht } = logging;
|
|
|
8
8
|
var $gnd = (s) => $gry($und(s));
|
|
9
9
|
var $bnd = (s) => $blu($und(s));
|
|
10
10
|
var $wnd = (s) => $wht($und(s));
|
|
11
|
-
var version = true ? "0.4.
|
|
11
|
+
var version = true ? "0.4.4" : "0.0.0-dev";
|
|
12
12
|
function help() {
|
|
13
13
|
console.log(`${$blu($und("Usage:"))}
|
|
14
14
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// expectation/async.ts
|
|
21
|
+
var async_exports = {};
|
|
22
|
+
__export(async_exports, {
|
|
23
|
+
toBeRejected: () => toBeRejected,
|
|
24
|
+
toBeRejectedWithError: () => toBeRejectedWithError,
|
|
25
|
+
toBeResolved: () => toBeResolved
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(async_exports);
|
|
28
|
+
var import_types = require("./types.cjs");
|
|
29
|
+
function toBeResolved(assert) {
|
|
30
|
+
return Promise.resolve().then(() => {
|
|
31
|
+
this.expects.toHaveProperty("then", (a) => a.toBeA("function"));
|
|
32
|
+
return Promise.allSettled([Promise.resolve(this.value)]);
|
|
33
|
+
}).then(([settlement]) => {
|
|
34
|
+
if (settlement.status === "fulfilled") {
|
|
35
|
+
if (this.negative)
|
|
36
|
+
throw new import_types.ExpectationError(this, "to be resolved");
|
|
37
|
+
if (assert)
|
|
38
|
+
assert(this.forValue(settlement.value));
|
|
39
|
+
} else if (!this.negative) {
|
|
40
|
+
throw new import_types.ExpectationError(this, "to be resolved");
|
|
41
|
+
}
|
|
42
|
+
return this.expects;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function toBeRejected(assert) {
|
|
46
|
+
return Promise.resolve().then(() => {
|
|
47
|
+
this.expects.toHaveProperty("then", (a) => a.toBeA("function"));
|
|
48
|
+
return Promise.allSettled([Promise.resolve(this.value)]);
|
|
49
|
+
}).then(([settlement]) => {
|
|
50
|
+
if (settlement.status === "rejected") {
|
|
51
|
+
if (this.negative)
|
|
52
|
+
throw new import_types.ExpectationError(this, "to be rejected");
|
|
53
|
+
if (assert)
|
|
54
|
+
assert(this.forValue(settlement.reason));
|
|
55
|
+
} else if (!this.negative) {
|
|
56
|
+
throw new import_types.ExpectationError(this, "to be rejected");
|
|
57
|
+
}
|
|
58
|
+
return this.expects;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function toBeRejectedWithError(...args) {
|
|
62
|
+
return this.negated.toBeRejected((assert) => (
|
|
63
|
+
// @ts-ignore // can't reconcile the types with overloads...
|
|
64
|
+
assert.toBeError(...args)
|
|
65
|
+
));
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
toBeRejected,
|
|
70
|
+
toBeRejectedWithError,
|
|
71
|
+
toBeResolved
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=async.cjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/expectation/async.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AAyCjC,SAAS,aAEL,QACqB;AAEvB,SAAO,QAAQ,QAAQ,EAClB,KAAK,MAAM;AACV,SAAK,QAAQ,eAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC;AAC9D,WAAO,QAAQ,WAAW,CAAE,QAAQ,QAAQ,KAAK,KAAK,CAAE,CAAC;AAAA,EAC3D,CAAC,EACA,KAAK,CAAC,CAAE,UAAW,MAAM;AACxB,QAAI,WAAW,WAAW,aAAa;AACrC,UAAI,KAAK;AAAU,cAAM,IAAI,8BAAiB,MAAM,gBAAgB;AACpE,UAAI;AAAQ,eAAO,KAAK,SAAS,WAAW,KAAK,CAAC;AAAA,IACpD,WAAW,CAAE,KAAK,UAAU;AAC1B,YAAM,IAAI,8BAAiB,MAAM,gBAAgB;AAAA,IACnD;AAEA,WAAO,KAAK;AAAA,EACd,CAAC;AACP;AAcA,SAAS,aAEL,QACqB;AACvB,SAAO,QAAQ,QAAQ,EAClB,KAAK,MAAM;AACV,SAAK,QAAQ,eAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC;AAC9D,WAAO,QAAQ,WAAW,CAAE,QAAQ,QAAQ,KAAK,KAAK,CAAE,CAAC;AAAA,EAC3D,CAAC,EACA,KAAK,CAAC,CAAE,UAAW,MAAM;AACxB,QAAI,WAAW,WAAW,YAAY;AACpC,UAAI,KAAK;AAAU,cAAM,IAAI,8BAAiB,MAAM,gBAAgB;AACpE,UAAI;AAAQ,eAAO,KAAK,SAAS,WAAW,MAAM,CAAC;AAAA,IACrD,WAAW,CAAE,KAAK,UAAU;AAC1B,YAAM,IAAI,8BAAiB,MAAM,gBAAgB;AAAA,IACnD;AAEA,WAAO,KAAK;AAAA,EACd,CAAC;AACP;AAsCA,SAAS,yBAEF,MAOkB;AACvB,SAAO,KAAK,QAAQ,aAAa,CAAC;AAAA;AAAA,IAEhC,OAAO,UAAU,GAAG,IAAI;AAAA,GAAC;AAC7B;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Expectations } from './expect';
|
|
2
|
+
import type { AssertedType, AssertionFunction, Constructor } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A {@link Promise} for an {@link Expectations} instance expecting a
|
|
5
|
+
* _then-able_ {@link PromiseLike}.
|
|
6
|
+
*
|
|
7
|
+
* Long story short: the {@link toBeResolved}, {@link toBeRejectedWithError} and
|
|
8
|
+
* {@link toBeRejected} expectations are asynchronous, henceforth they return
|
|
9
|
+
* the first {@link Promise} to an {@link Expectations} instance. They also
|
|
10
|
+
* ensure that the value being expected is a _then-able_ {@link PromiseLike}.
|
|
11
|
+
*/
|
|
12
|
+
type ExpectationsPromise<E, T2 = unknown> = unknown extends T2 ? E extends Expectations<infer T1> ? Promise<Expectations<PromiseLike<Awaited<T1>>>> : Promise<Expectations<PromiseLike<unknown>>> : Promise<Expectations<PromiseLike<T2>>>;
|
|
13
|
+
/** Expects the value to be a _resolved_ {@link PromiseLike}. */
|
|
14
|
+
declare function toBeResolved<T>(this: T): ExpectationsPromise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Expects the value to be a _resolved_ {@link Promise}, and asserts the
|
|
17
|
+
* resolved result with the specified callback.
|
|
18
|
+
*/
|
|
19
|
+
declare function toBeResolved<T, A extends AssertionFunction>(this: T, assert: A): ExpectationsPromise<T, AssertedType<A>>;
|
|
20
|
+
/** Expect the value to be a _rejected_ {@link Promise}. */
|
|
21
|
+
declare function toBeRejected<T>(this: T): ExpectationsPromise<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Expect the value to be a _rejected_ {@link Promise}, and asserts the
|
|
24
|
+
* rejection reason with the specified callback.
|
|
25
|
+
*/
|
|
26
|
+
declare function toBeRejected<T>(this: T, assert: AssertionFunction): ExpectationsPromise<T>;
|
|
27
|
+
/** Expect the value to be a {@link Promise} _rejected_ by an {@link Error}. */
|
|
28
|
+
declare function toBeRejectedWithError<T>(this: T): ExpectationsPromise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
31
|
+
* with the specified _message_.
|
|
32
|
+
*/
|
|
33
|
+
declare function toBeRejectedWithError<T>(this: T, message: string): ExpectationsPromise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
36
|
+
* with its _message_ matching the specified {@link RegExp}.
|
|
37
|
+
*/
|
|
38
|
+
declare function toBeRejectedWithError<T>(this: T, message: RegExp): ExpectationsPromise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
41
|
+
* of the specified _type_.
|
|
42
|
+
*/
|
|
43
|
+
declare function toBeRejectedWithError<T>(this: T, constructor: Constructor<Error>): ExpectationsPromise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
46
|
+
* of the specified _type_ and with the specified _message_.
|
|
47
|
+
*/
|
|
48
|
+
declare function toBeRejectedWithError<T>(this: T, constructor: Constructor<Error>, message: string): ExpectationsPromise<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Expect the value to be a {@link Promise} _rejected_ by an {@link Error}
|
|
51
|
+
* of the specified _type_ and with the specified _message_.
|
|
52
|
+
*/
|
|
53
|
+
declare function toBeRejectedWithError<T>(this: T, constructor: Constructor<Error>, message: RegExp): ExpectationsPromise<T>;
|
|
54
|
+
export { toBeResolved, toBeRejected, toBeRejectedWithError };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// expectation/async.ts
|
|
2
|
+
import { ExpectationError } from "./types.mjs";
|
|
3
|
+
function toBeResolved(assert) {
|
|
4
|
+
return Promise.resolve().then(() => {
|
|
5
|
+
this.expects.toHaveProperty("then", (a) => a.toBeA("function"));
|
|
6
|
+
return Promise.allSettled([Promise.resolve(this.value)]);
|
|
7
|
+
}).then(([settlement]) => {
|
|
8
|
+
if (settlement.status === "fulfilled") {
|
|
9
|
+
if (this.negative)
|
|
10
|
+
throw new ExpectationError(this, "to be resolved");
|
|
11
|
+
if (assert)
|
|
12
|
+
assert(this.forValue(settlement.value));
|
|
13
|
+
} else if (!this.negative) {
|
|
14
|
+
throw new ExpectationError(this, "to be resolved");
|
|
15
|
+
}
|
|
16
|
+
return this.expects;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function toBeRejected(assert) {
|
|
20
|
+
return Promise.resolve().then(() => {
|
|
21
|
+
this.expects.toHaveProperty("then", (a) => a.toBeA("function"));
|
|
22
|
+
return Promise.allSettled([Promise.resolve(this.value)]);
|
|
23
|
+
}).then(([settlement]) => {
|
|
24
|
+
if (settlement.status === "rejected") {
|
|
25
|
+
if (this.negative)
|
|
26
|
+
throw new ExpectationError(this, "to be rejected");
|
|
27
|
+
if (assert)
|
|
28
|
+
assert(this.forValue(settlement.reason));
|
|
29
|
+
} else if (!this.negative) {
|
|
30
|
+
throw new ExpectationError(this, "to be rejected");
|
|
31
|
+
}
|
|
32
|
+
return this.expects;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function toBeRejectedWithError(...args) {
|
|
36
|
+
return this.negated.toBeRejected((assert) => (
|
|
37
|
+
// @ts-ignore // can't reconcile the types with overloads...
|
|
38
|
+
assert.toBeError(...args)
|
|
39
|
+
));
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
toBeRejected,
|
|
43
|
+
toBeRejectedWithError,
|
|
44
|
+
toBeResolved
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=async.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/expectation/async.ts"],
|
|
4
|
+
"mappings": ";AAAA,SAAS,wBAAwB;AAyCjC,SAAS,aAEL,QACqB;AAEvB,SAAO,QAAQ,QAAQ,EAClB,KAAK,MAAM;AACV,SAAK,QAAQ,eAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC;AAC9D,WAAO,QAAQ,WAAW,CAAE,QAAQ,QAAQ,KAAK,KAAK,CAAE,CAAC;AAAA,EAC3D,CAAC,EACA,KAAK,CAAC,CAAE,UAAW,MAAM;AACxB,QAAI,WAAW,WAAW,aAAa;AACrC,UAAI,KAAK;AAAU,cAAM,IAAI,iBAAiB,MAAM,gBAAgB;AACpE,UAAI;AAAQ,eAAO,KAAK,SAAS,WAAW,KAAK,CAAC;AAAA,IACpD,WAAW,CAAE,KAAK,UAAU;AAC1B,YAAM,IAAI,iBAAiB,MAAM,gBAAgB;AAAA,IACnD;AAEA,WAAO,KAAK;AAAA,EACd,CAAC;AACP;AAcA,SAAS,aAEL,QACqB;AACvB,SAAO,QAAQ,QAAQ,EAClB,KAAK,MAAM;AACV,SAAK,QAAQ,eAAe,QAAQ,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC;AAC9D,WAAO,QAAQ,WAAW,CAAE,QAAQ,QAAQ,KAAK,KAAK,CAAE,CAAC;AAAA,EAC3D,CAAC,EACA,KAAK,CAAC,CAAE,UAAW,MAAM;AACxB,QAAI,WAAW,WAAW,YAAY;AACpC,UAAI,KAAK;AAAU,cAAM,IAAI,iBAAiB,MAAM,gBAAgB;AACpE,UAAI;AAAQ,eAAO,KAAK,SAAS,WAAW,MAAM,CAAC;AAAA,IACrD,WAAW,CAAE,KAAK,UAAU;AAC1B,YAAM,IAAI,iBAAiB,MAAM,gBAAgB;AAAA,IACnD;AAEA,WAAO,KAAK;AAAA,EACd,CAAC;AACP;AAsCA,SAAS,yBAEF,MAOkB;AACvB,SAAO,KAAK,QAAQ,aAAa,CAAC;AAAA;AAAA,IAEhC,OAAO,UAAU,GAAG,IAAI;AAAA,GAAC;AAC7B;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -20,197 +20,169 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// expectation/basic.ts
|
|
21
21
|
var basic_exports = {};
|
|
22
22
|
__export(basic_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
toBeA: () => toBeA,
|
|
24
|
+
toBeCloseTo: () => toBeCloseTo,
|
|
25
|
+
toBeError: () => toBeError,
|
|
26
|
+
toBeGreaterThan: () => toBeGreaterThan,
|
|
27
|
+
toBeGreaterThanOrEqual: () => toBeGreaterThanOrEqual,
|
|
28
|
+
toBeInstanceOf: () => toBeInstanceOf,
|
|
29
|
+
toBeLessThan: () => toBeLessThan,
|
|
30
|
+
toBeLessThanOrEqual: () => toBeLessThanOrEqual,
|
|
31
|
+
toBeWithinRange: () => toBeWithinRange,
|
|
32
|
+
toEqual: () => toEqual,
|
|
33
|
+
toHaveLength: () => toHaveLength,
|
|
34
|
+
toHaveProperty: () => toHaveProperty,
|
|
35
|
+
toHaveSize: () => toHaveSize,
|
|
36
|
+
toMatch: () => toMatch,
|
|
37
|
+
toStrictlyEqual: () => toStrictlyEqual
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(basic_exports);
|
|
40
40
|
var import_diff = require("./diff.cjs");
|
|
41
41
|
var import_types = require("./types.cjs");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
if (actualLength === length === negative) {
|
|
141
|
-
throw new import_types.ExpectationError(context, negative, `to have length ${(0, import_types.stringifyValue)(length)}`);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
var ToHaveProperty = class {
|
|
146
|
-
expect(context, negative, prop, assert) {
|
|
147
|
-
context.toBeDefined();
|
|
148
|
-
const match = context.value[prop] !== void 0;
|
|
149
|
-
if (match === negative) {
|
|
150
|
-
throw new import_types.ExpectationError(context, negative, `to have property "${String(prop)}"`);
|
|
151
|
-
} else if (match && assert) {
|
|
152
|
-
try {
|
|
153
|
-
assert(context.forProperty(prop));
|
|
154
|
-
} catch (error) {
|
|
155
|
-
if (error instanceof import_types.ExpectationError && error.diff) {
|
|
156
|
-
error.diff = {
|
|
157
|
-
diff: true,
|
|
158
|
-
value: context.value,
|
|
159
|
-
props: { [prop]: error.diff }
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
throw error;
|
|
42
|
+
function toBeA(type, assert) {
|
|
43
|
+
const match = (0, import_types.typeOf)(this.value) === type;
|
|
44
|
+
if (match === this.negative) {
|
|
45
|
+
throw new import_types.ExpectationError(this, `to be ${(0, import_types.prefixType)(type)}`);
|
|
46
|
+
} else if (assert) {
|
|
47
|
+
assert(this.expects);
|
|
48
|
+
}
|
|
49
|
+
return this.expects;
|
|
50
|
+
}
|
|
51
|
+
function toBeCloseTo(value, delta) {
|
|
52
|
+
const min = value - delta;
|
|
53
|
+
const max = value + delta;
|
|
54
|
+
return this.negated.toBeWithinRange(min, max);
|
|
55
|
+
}
|
|
56
|
+
function toBeError(...args) {
|
|
57
|
+
const [constructor, message] = typeof args[0] === "function" ? [args[0], args[1]] : [Error, args[0]];
|
|
58
|
+
this.negated.toBeInstanceOf(constructor);
|
|
59
|
+
if (this.negative || message === void 0)
|
|
60
|
+
return this.expects;
|
|
61
|
+
return this.expects.toHaveProperty("message", (assert) => {
|
|
62
|
+
assert.toBeA("string");
|
|
63
|
+
return typeof message === "string" ? assert.toStrictlyEqual(message) : assert.toMatch(message);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function toBeGreaterThan(value) {
|
|
67
|
+
(0, import_types.assertContextType)(this, typeof value);
|
|
68
|
+
if (this.value > value !== this.negative)
|
|
69
|
+
return this.expects;
|
|
70
|
+
throw new import_types.ExpectationError(this, `to be greater than ${(0, import_types.stringifyValue)(value)}`);
|
|
71
|
+
}
|
|
72
|
+
function toBeGreaterThanOrEqual(value) {
|
|
73
|
+
(0, import_types.assertContextType)(this, typeof value);
|
|
74
|
+
if (this.value >= value !== this.negative)
|
|
75
|
+
return this.expects;
|
|
76
|
+
throw new import_types.ExpectationError(this, `to be greater than or equal to ${(0, import_types.stringifyValue)(value)}`);
|
|
77
|
+
}
|
|
78
|
+
function toBeInstanceOf(value) {
|
|
79
|
+
const match = this.value instanceof value;
|
|
80
|
+
if (match !== this.negative)
|
|
81
|
+
return this.expects;
|
|
82
|
+
throw new import_types.ExpectationError(this, `to be an instance of ${(0, import_types.stringifyConstructor)(value)}`);
|
|
83
|
+
}
|
|
84
|
+
function toBeLessThan(value) {
|
|
85
|
+
(0, import_types.assertContextType)(this, typeof value);
|
|
86
|
+
if (this.value < value !== this.negative)
|
|
87
|
+
return this.expects;
|
|
88
|
+
throw new import_types.ExpectationError(this, `to be less than ${(0, import_types.stringifyValue)(value)}`);
|
|
89
|
+
}
|
|
90
|
+
function toBeLessThanOrEqual(value) {
|
|
91
|
+
(0, import_types.assertContextType)(this, typeof value);
|
|
92
|
+
if (this.value <= value !== this.negative)
|
|
93
|
+
return this.expects;
|
|
94
|
+
throw new import_types.ExpectationError(this, `to be less than or equal to ${(0, import_types.stringifyValue)(value)}`);
|
|
95
|
+
}
|
|
96
|
+
function toBeWithinRange(min, max) {
|
|
97
|
+
if (max < min) {
|
|
98
|
+
const num = max;
|
|
99
|
+
max = min;
|
|
100
|
+
min = num;
|
|
101
|
+
}
|
|
102
|
+
(0, import_types.assertContextType)(this, typeof min);
|
|
103
|
+
if ((this.value >= min && this.value <= max) !== this.negative)
|
|
104
|
+
return this.expects;
|
|
105
|
+
throw new import_types.ExpectationError(this, `to be within ${(0, import_types.stringifyValue)(min)}...${(0, import_types.stringifyValue)(max)}`);
|
|
106
|
+
}
|
|
107
|
+
function toEqual(expected) {
|
|
108
|
+
const result = (0, import_diff.diff)(this.value, expected);
|
|
109
|
+
if (result.diff === this.negative)
|
|
110
|
+
return this.expects;
|
|
111
|
+
throw new import_types.ExpectationError(this, `to equal ${(0, import_types.stringifyValue)(expected)}`, result);
|
|
112
|
+
}
|
|
113
|
+
function toHaveLength(length) {
|
|
114
|
+
this.expects.toBeDefined();
|
|
115
|
+
const actualLength = this.value.length;
|
|
116
|
+
if (typeof actualLength !== "number") {
|
|
117
|
+
throw new import_types.ExpectationError(this, 'to have a numeric "length" property', false);
|
|
118
|
+
}
|
|
119
|
+
if (actualLength === length === this.negative) {
|
|
120
|
+
throw new import_types.ExpectationError(this, `to have length ${(0, import_types.stringifyValue)(length)}`);
|
|
121
|
+
}
|
|
122
|
+
return this.expects;
|
|
123
|
+
}
|
|
124
|
+
function toHaveProperty(prop, assert) {
|
|
125
|
+
this.expects.toBeDefined();
|
|
126
|
+
const match = this.value[prop] !== void 0;
|
|
127
|
+
if (match === this.negative) {
|
|
128
|
+
throw new import_types.ExpectationError(this, `to have property "${String(prop)}"`);
|
|
129
|
+
} else if (match && assert) {
|
|
130
|
+
try {
|
|
131
|
+
assert(this.forProperty(prop));
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error instanceof import_types.ExpectationError && error.diff) {
|
|
134
|
+
error.diff = {
|
|
135
|
+
diff: true,
|
|
136
|
+
value: this.value,
|
|
137
|
+
props: { [prop]: error.diff }
|
|
138
|
+
};
|
|
163
139
|
}
|
|
140
|
+
throw error;
|
|
164
141
|
}
|
|
165
142
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return;
|
|
194
|
-
const diff2 = negative ? void 0 : { diff: true, value, expected };
|
|
195
|
-
throw new import_types.ExpectationError(context, negative, `to strictly equal ${(0, import_types.stringifyValue)(expected)}`, diff2);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
143
|
+
return this.expects;
|
|
144
|
+
}
|
|
145
|
+
function toHaveSize(size) {
|
|
146
|
+
this.expects.toBeDefined();
|
|
147
|
+
const actualSize = this.value.size;
|
|
148
|
+
if (typeof actualSize !== "number") {
|
|
149
|
+
throw new import_types.ExpectationError(this, 'to have a numeric "size" property', false);
|
|
150
|
+
}
|
|
151
|
+
if (actualSize === size === this.negative) {
|
|
152
|
+
throw new import_types.ExpectationError(this, `to have size ${(0, import_types.stringifyValue)(size)}`);
|
|
153
|
+
}
|
|
154
|
+
return this.expects;
|
|
155
|
+
}
|
|
156
|
+
function toMatch(expr) {
|
|
157
|
+
(0, import_types.assertContextType)(this, "string");
|
|
158
|
+
const match = !!this.value.match(expr);
|
|
159
|
+
if (match !== this.negative)
|
|
160
|
+
return this.expects;
|
|
161
|
+
throw new import_types.ExpectationError(this, `to match ${(0, import_types.stringifyValue)(expr)}`);
|
|
162
|
+
}
|
|
163
|
+
function toStrictlyEqual(expected) {
|
|
164
|
+
const match = this.value === expected;
|
|
165
|
+
if (match !== this.negative)
|
|
166
|
+
return this.expects;
|
|
167
|
+
const diff2 = this.negative ? void 0 : { diff: true, value: this.value, expected };
|
|
168
|
+
throw new import_types.ExpectationError(this, `to strictly equal ${(0, import_types.stringifyValue)(expected)}`, diff2);
|
|
169
|
+
}
|
|
198
170
|
// Annotate the CommonJS export names for ESM import in node:
|
|
199
171
|
0 && (module.exports = {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
172
|
+
toBeA,
|
|
173
|
+
toBeCloseTo,
|
|
174
|
+
toBeError,
|
|
175
|
+
toBeGreaterThan,
|
|
176
|
+
toBeGreaterThanOrEqual,
|
|
177
|
+
toBeInstanceOf,
|
|
178
|
+
toBeLessThan,
|
|
179
|
+
toBeLessThanOrEqual,
|
|
180
|
+
toBeWithinRange,
|
|
181
|
+
toEqual,
|
|
182
|
+
toHaveLength,
|
|
183
|
+
toHaveProperty,
|
|
184
|
+
toHaveSize,
|
|
185
|
+
toMatch,
|
|
186
|
+
toStrictlyEqual
|
|
215
187
|
});
|
|
216
188
|
//# sourceMappingURL=basic.cjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/expectation/basic.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AA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