hein 1.4.2 → 2.0.0-alpha.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/CHANGELOG.md +8 -0
- package/ESM_MIGRATION_NOTES.md +6 -0
- package/README.md +46 -7
- package/dist/assert-9EsvfQwn.d.cts +483 -0
- package/dist/assert-9EsvfQwn.d.cts.map +1 -0
- package/dist/assert-B_vcZS90.d.ts +481 -0
- package/dist/assert-B_vcZS90.d.ts.map +1 -0
- package/dist/assert-DZjgWjOw.cjs +1626 -0
- package/dist/assert-DZjgWjOw.cjs.map +1 -0
- package/dist/assert-kFXp7i_B.js +1260 -0
- package/dist/assert-kFXp7i_B.js.map +1 -0
- package/dist/assert.cjs +53 -0
- package/dist/assert.d.cts +3 -0
- package/dist/assert.d.ts +3 -27
- package/dist/assert.js +3 -84
- package/dist/chunk-CTAAG5j7.js +13 -0
- package/dist/expect.types-DPl6xY56.d.ts +99 -0
- package/dist/expect.types-DPl6xY56.d.ts.map +1 -0
- package/dist/expect.types-s8icgWp5.d.cts +99 -0
- package/dist/expect.types-s8icgWp5.d.cts.map +1 -0
- package/dist/expect.types.cjs +0 -0
- package/dist/expect.types.d.cts +3 -0
- package/dist/expect.types.d.ts +3 -66
- package/dist/expect.types.js +1 -4
- package/dist/index.cjs +596 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +573 -27
- package/dist/index.js.map +1 -1
- package/dist/throws-BrCCeBBl.d.ts +42 -0
- package/dist/throws-BrCCeBBl.d.ts.map +1 -0
- package/dist/throws-D7JsW4NM.d.cts +40 -0
- package/dist/throws-D7JsW4NM.d.cts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +31 -18
- package/tsdown.config.ts +9 -0
- package/dist/assert/deep-equal.d.ts +0 -2
- package/dist/assert/deep-equal.d.ts.map +0 -1
- package/dist/assert/deep-equal.js +0 -26
- package/dist/assert/deep-equal.js.map +0 -1
- package/dist/assert/deep-has-property.d.ts +0 -20
- package/dist/assert/deep-has-property.d.ts.map +0 -1
- package/dist/assert/deep-has-property.js +0 -50
- package/dist/assert/deep-has-property.js.map +0 -1
- package/dist/assert/ends-with.d.ts +0 -11
- package/dist/assert/ends-with.d.ts.map +0 -1
- package/dist/assert/ends-with.js +0 -30
- package/dist/assert/ends-with.js.map +0 -1
- package/dist/assert/equal.d.ts +0 -9
- package/dist/assert/equal.d.ts.map +0 -1
- package/dist/assert/equal.js +0 -21
- package/dist/assert/equal.js.map +0 -1
- package/dist/assert/greater-than-equal.d.ts +0 -9
- package/dist/assert/greater-than-equal.d.ts.map +0 -1
- package/dist/assert/greater-than-equal.js +0 -20
- package/dist/assert/greater-than-equal.js.map +0 -1
- package/dist/assert/greater-than.d.ts +0 -9
- package/dist/assert/greater-than.d.ts.map +0 -1
- package/dist/assert/greater-than.js +0 -20
- package/dist/assert/greater-than.js.map +0 -1
- package/dist/assert/has-keys.d.ts +0 -14
- package/dist/assert/has-keys.d.ts.map +0 -1
- package/dist/assert/has-keys.js +0 -47
- package/dist/assert/has-keys.js.map +0 -1
- package/dist/assert/has-members.d.ts +0 -46
- package/dist/assert/has-members.d.ts.map +0 -1
- package/dist/assert/has-members.js +0 -58
- package/dist/assert/has-members.js.map +0 -1
- package/dist/assert/has-property.d.ts +0 -20
- package/dist/assert/has-property.d.ts.map +0 -1
- package/dist/assert/has-property.js +0 -47
- package/dist/assert/has-property.js.map +0 -1
- package/dist/assert/has-size.d.ts +0 -40
- package/dist/assert/has-size.d.ts.map +0 -1
- package/dist/assert/has-size.js +0 -68
- package/dist/assert/has-size.js.map +0 -1
- package/dist/assert/in-ballpark.d.ts +0 -14
- package/dist/assert/in-ballpark.d.ts.map +0 -1
- package/dist/assert/in-ballpark.js +0 -26
- package/dist/assert/in-ballpark.js.map +0 -1
- package/dist/assert/includes.d.ts +0 -22
- package/dist/assert/includes.d.ts.map +0 -1
- package/dist/assert/includes.js +0 -32
- package/dist/assert/includes.js.map +0 -1
- package/dist/assert/instance-of.d.ts +0 -13
- package/dist/assert/instance-of.d.ts.map +0 -1
- package/dist/assert/instance-of.js +0 -35
- package/dist/assert/instance-of.js.map +0 -1
- package/dist/assert/is-after.d.ts +0 -9
- package/dist/assert/is-after.d.ts.map +0 -1
- package/dist/assert/is-after.js +0 -27
- package/dist/assert/is-after.js.map +0 -1
- package/dist/assert/is-before.d.ts +0 -9
- package/dist/assert/is-before.d.ts.map +0 -1
- package/dist/assert/is-before.js +0 -27
- package/dist/assert/is-before.js.map +0 -1
- package/dist/assert/is-between.d.ts +0 -13
- package/dist/assert/is-between.d.ts.map +0 -1
- package/dist/assert/is-between.js +0 -38
- package/dist/assert/is-between.js.map +0 -1
- package/dist/assert/is-empty.d.ts +0 -29
- package/dist/assert/is-empty.d.ts.map +0 -1
- package/dist/assert/is-empty.js +0 -48
- package/dist/assert/is-empty.js.map +0 -1
- package/dist/assert/is-type.d.ts +0 -94
- package/dist/assert/is-type.d.ts.map +0 -1
- package/dist/assert/is-type.js +0 -32
- package/dist/assert/is-type.js.map +0 -1
- package/dist/assert/less-than-equal.d.ts +0 -9
- package/dist/assert/less-than-equal.d.ts.map +0 -1
- package/dist/assert/less-than-equal.js +0 -27
- package/dist/assert/less-than-equal.js.map +0 -1
- package/dist/assert/less-than.d.ts +0 -9
- package/dist/assert/less-than.d.ts.map +0 -1
- package/dist/assert/less-than.js +0 -20
- package/dist/assert/less-than.js.map +0 -1
- package/dist/assert/match.d.ts +0 -13
- package/dist/assert/match.d.ts.map +0 -1
- package/dist/assert/match.js +0 -29
- package/dist/assert/match.js.map +0 -1
- package/dist/assert/rejects.d.ts +0 -33
- package/dist/assert/rejects.d.ts.map +0 -1
- package/dist/assert/rejects.js +0 -48
- package/dist/assert/rejects.js.map +0 -1
- package/dist/assert/round-to.d.ts +0 -13
- package/dist/assert/round-to.d.ts.map +0 -1
- package/dist/assert/round-to.js +0 -43
- package/dist/assert/round-to.js.map +0 -1
- package/dist/assert/starts-with.d.ts +0 -12
- package/dist/assert/starts-with.d.ts.map +0 -1
- package/dist/assert/starts-with.js +0 -30
- package/dist/assert/starts-with.js.map +0 -1
- package/dist/assert/throws.d.ts +0 -33
- package/dist/assert/throws.d.ts.map +0 -1
- package/dist/assert/throws.js +0 -40
- package/dist/assert/throws.js.map +0 -1
- package/dist/assert.d.ts.map +0 -1
- package/dist/assert.js.map +0 -1
- package/dist/expect/after.d.ts +0 -11
- package/dist/expect/after.d.ts.map +0 -1
- package/dist/expect/after.js +0 -18
- package/dist/expect/after.js.map +0 -1
- package/dist/expect/ballpark.d.ts +0 -12
- package/dist/expect/ballpark.d.ts.map +0 -1
- package/dist/expect/ballpark.js +0 -18
- package/dist/expect/ballpark.js.map +0 -1
- package/dist/expect/before.d.ts +0 -11
- package/dist/expect/before.d.ts.map +0 -1
- package/dist/expect/before.js +0 -18
- package/dist/expect/before.js.map +0 -1
- package/dist/expect/between.d.ts +0 -21
- package/dist/expect/between.d.ts.map +0 -1
- package/dist/expect/between.js +0 -18
- package/dist/expect/between.js.map +0 -1
- package/dist/expect/empty.d.ts +0 -16
- package/dist/expect/empty.d.ts.map +0 -1
- package/dist/expect/empty.js +0 -18
- package/dist/expect/empty.js.map +0 -1
- package/dist/expect/end-with.d.ts +0 -12
- package/dist/expect/end-with.d.ts.map +0 -1
- package/dist/expect/end-with.js +0 -18
- package/dist/expect/end-with.js.map +0 -1
- package/dist/expect/eql.d.ts +0 -11
- package/dist/expect/eql.d.ts.map +0 -1
- package/dist/expect/eql.js +0 -22
- package/dist/expect/eql.js.map +0 -1
- package/dist/expect/equal-shorthand.d.ts +0 -14
- package/dist/expect/equal-shorthand.d.ts.map +0 -1
- package/dist/expect/equal-shorthand.js +0 -34
- package/dist/expect/equal-shorthand.js.map +0 -1
- package/dist/expect/equal.d.ts +0 -14
- package/dist/expect/equal.d.ts.map +0 -1
- package/dist/expect/equal.js +0 -28
- package/dist/expect/equal.js.map +0 -1
- package/dist/expect/excluding.d.ts +0 -11
- package/dist/expect/excluding.d.ts.map +0 -1
- package/dist/expect/excluding.js +0 -14
- package/dist/expect/excluding.js.map +0 -1
- package/dist/expect/greater-than-equal.d.ts +0 -32
- package/dist/expect/greater-than-equal.d.ts.map +0 -1
- package/dist/expect/greater-than-equal.js +0 -20
- package/dist/expect/greater-than-equal.js.map +0 -1
- package/dist/expect/greater-than.d.ts +0 -32
- package/dist/expect/greater-than.d.ts.map +0 -1
- package/dist/expect/greater-than.js +0 -20
- package/dist/expect/greater-than.js.map +0 -1
- package/dist/expect/has-property.d.ts +0 -36
- package/dist/expect/has-property.d.ts.map +0 -1
- package/dist/expect/has-property.js +0 -22
- package/dist/expect/has-property.js.map +0 -1
- package/dist/expect/include.d.ts +0 -25
- package/dist/expect/include.d.ts.map +0 -1
- package/dist/expect/include.js +0 -22
- package/dist/expect/include.js.map +0 -1
- package/dist/expect/instance-of-shorthand.d.ts +0 -34
- package/dist/expect/instance-of-shorthand.d.ts.map +0 -1
- package/dist/expect/instance-of-shorthand.js +0 -22
- package/dist/expect/instance-of-shorthand.js.map +0 -1
- package/dist/expect/instance-of.d.ts +0 -11
- package/dist/expect/instance-of.d.ts.map +0 -1
- package/dist/expect/instance-of.js +0 -18
- package/dist/expect/instance-of.js.map +0 -1
- package/dist/expect/keys.d.ts +0 -17
- package/dist/expect/keys.d.ts.map +0 -1
- package/dist/expect/keys.js +0 -18
- package/dist/expect/keys.js.map +0 -1
- package/dist/expect/length.d.ts +0 -28
- package/dist/expect/length.d.ts.map +0 -1
- package/dist/expect/length.js +0 -19
- package/dist/expect/length.js.map +0 -1
- package/dist/expect/less-than-equal.d.ts +0 -32
- package/dist/expect/less-than-equal.d.ts.map +0 -1
- package/dist/expect/less-than-equal.js +0 -20
- package/dist/expect/less-than-equal.js.map +0 -1
- package/dist/expect/less-than.d.ts +0 -32
- package/dist/expect/less-than.d.ts.map +0 -1
- package/dist/expect/less-than.js +0 -20
- package/dist/expect/less-than.js.map +0 -1
- package/dist/expect/match.d.ts +0 -10
- package/dist/expect/match.d.ts.map +0 -1
- package/dist/expect/match.js +0 -18
- package/dist/expect/match.js.map +0 -1
- package/dist/expect/members.d.ts +0 -20
- package/dist/expect/members.d.ts.map +0 -1
- package/dist/expect/members.js +0 -32
- package/dist/expect/members.js.map +0 -1
- package/dist/expect/reject.d.ts +0 -12
- package/dist/expect/reject.d.ts.map +0 -1
- package/dist/expect/reject.js +0 -13
- package/dist/expect/reject.js.map +0 -1
- package/dist/expect/round-to.d.ts +0 -12
- package/dist/expect/round-to.d.ts.map +0 -1
- package/dist/expect/round-to.js +0 -18
- package/dist/expect/round-to.js.map +0 -1
- package/dist/expect/start-with.d.ts +0 -12
- package/dist/expect/start-with.d.ts.map +0 -1
- package/dist/expect/start-with.js +0 -18
- package/dist/expect/start-with.js.map +0 -1
- package/dist/expect/throw.d.ts +0 -12
- package/dist/expect/throw.d.ts.map +0 -1
- package/dist/expect/throw.js +0 -13
- package/dist/expect/throw.js.map +0 -1
- package/dist/expect/type-shorthand.d.ts +0 -66
- package/dist/expect/type-shorthand.d.ts.map +0 -1
- package/dist/expect/type-shorthand.js +0 -34
- package/dist/expect/type-shorthand.js.map +0 -1
- package/dist/expect/type.d.ts +0 -10
- package/dist/expect/type.d.ts.map +0 -1
- package/dist/expect/type.js +0 -18
- package/dist/expect/type.js.map +0 -1
- package/dist/expect.d.ts +0 -33
- package/dist/expect.d.ts.map +0 -1
- package/dist/expect.js +0 -88
- package/dist/expect.js.map +0 -1
- package/dist/expect.types.d.ts.map +0 -1
- package/dist/expect.types.js.map +0 -1
- package/dist/mixins.d.ts +0 -26
- package/dist/mixins.d.ts.map +0 -1
- package/dist/mixins.js +0 -9
- package/dist/mixins.js.map +0 -1
- package/dist/utils/cast-array.d.ts +0 -2
- package/dist/utils/cast-array.d.ts.map +0 -1
- package/dist/utils/cast-array.js +0 -14
- package/dist/utils/cast-array.js.map +0 -1
- package/dist/utils/chain.d.ts +0 -3
- package/dist/utils/chain.d.ts.map +0 -1
- package/dist/utils/chain.js +0 -21
- package/dist/utils/chain.js.map +0 -1
- package/dist/utils/fail.d.ts +0 -6
- package/dist/utils/fail.d.ts.map +0 -1
- package/dist/utils/fail.js +0 -13
- package/dist/utils/fail.js.map +0 -1
- package/dist/utils/get-size.d.ts +0 -2
- package/dist/utils/get-size.d.ts.map +0 -1
- package/dist/utils/get-size.js +0 -24
- package/dist/utils/get-size.js.map +0 -1
- package/dist/utils/get-type.d.ts +0 -3
- package/dist/utils/get-type.d.ts.map +0 -1
- package/dist/utils/get-type.js +0 -17
- package/dist/utils/get-type.js.map +0 -1
- package/dist/utils/match.d.ts +0 -15
- package/dist/utils/match.d.ts.map +0 -1
- package/dist/utils/match.js +0 -150
- package/dist/utils/match.js.map +0 -1
- package/dist/utils/process-error.d.ts +0 -11
- package/dist/utils/process-error.d.ts.map +0 -1
- package/dist/utils/process-error.js +0 -98
- package/dist/utils/process-error.js.map +0 -1
- package/dist/utils/types.d.ts +0 -4
- package/dist/utils/types.d.ts.map +0 -1
- package/dist/utils/types.js +0 -3
- package/dist/utils/types.js.map +0 -1
- package/dist/utils/validate-numeric-and-dates.d.ts +0 -2
- package/dist/utils/validate-numeric-and-dates.d.ts.map +0 -1
- package/dist/utils/validate-numeric-and-dates.js +0 -15
- package/dist/utils/validate-numeric-and-dates.js.map +0 -1
- package/dist/utils/xor.d.ts +0 -2
- package/dist/utils/xor.d.ts.map +0 -1
- package/dist/utils/xor.js +0 -8
- package/dist/utils/xor.js.map +0 -1
|
@@ -0,0 +1,1260 @@
|
|
|
1
|
+
import { __export } from "./chunk-CTAAG5j7.js";
|
|
2
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
3
|
+
import { AssertionError, createAssertion, stringify } from "hein-assertion-utils";
|
|
4
|
+
import isObjectLike from "lodash/isObjectLike.js";
|
|
5
|
+
import isPlainObject from "lodash/isPlainObject.js";
|
|
6
|
+
import get from "lodash/get.js";
|
|
7
|
+
import has from "lodash/has.js";
|
|
8
|
+
import castArray from "lodash/castArray.js";
|
|
9
|
+
|
|
10
|
+
//#region src/utils/xor.ts
|
|
11
|
+
const xor = (a, b) => {
|
|
12
|
+
return a && !b || !a && b;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/utils/match.ts
|
|
17
|
+
const evaluationSymbol = Symbol();
|
|
18
|
+
const createEvaluation = (callback) => {
|
|
19
|
+
const evaluation = (value) => {
|
|
20
|
+
return callback(value);
|
|
21
|
+
};
|
|
22
|
+
evaluation[evaluationSymbol] = true;
|
|
23
|
+
return evaluation;
|
|
24
|
+
};
|
|
25
|
+
const any = createEvaluation(() => true);
|
|
26
|
+
const isEvaluation = (value) => value && value[evaluationSymbol];
|
|
27
|
+
const match$1 = (actual, expected, { mutate = false, partial = false } = {}) => {
|
|
28
|
+
if (actual === expected) return true;
|
|
29
|
+
if (isEvaluation(expected)) return expected(actual);
|
|
30
|
+
if (actual == null || expected == null || !isObjectLike(actual) && !isObjectLike(expected)) return actual !== actual && expected !== expected;
|
|
31
|
+
let result = true;
|
|
32
|
+
if (actual instanceof Map || expected instanceof Map) {
|
|
33
|
+
if (!(actual instanceof Map && expected instanceof Map)) return false;
|
|
34
|
+
if (actual.size !== expected.size && !partial) result = false;
|
|
35
|
+
for (const [key, value] of expected.entries()) {
|
|
36
|
+
if (!actual.has(key)) {
|
|
37
|
+
result = false;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const actualValue = actual.get(key);
|
|
41
|
+
if (mutate && isEvaluation(value)) {
|
|
42
|
+
expected.set(key, actualValue);
|
|
43
|
+
result && (result = value(actualValue));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
result = match$1(actualValue, value, {
|
|
47
|
+
mutate,
|
|
48
|
+
partial
|
|
49
|
+
}) && result;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
if (actual instanceof WeakMap || expected instanceof WeakMap) return false;
|
|
55
|
+
if (actual instanceof Set || expected instanceof Set) {
|
|
56
|
+
if (!(actual instanceof Set && expected instanceof Set)) return false;
|
|
57
|
+
if (actual.size !== expected.size && !partial) return false;
|
|
58
|
+
return [...expected.values()].every((value) => {
|
|
59
|
+
return actual.has(value);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (actual instanceof WeakSet || expected instanceof WeakSet) return false;
|
|
63
|
+
if (actual instanceof Date || expected instanceof Date) {
|
|
64
|
+
if (!(actual instanceof Date && expected instanceof Date)) {
|
|
65
|
+
const date1 = new Date(actual);
|
|
66
|
+
const date2 = new Date(expected);
|
|
67
|
+
return date1.getTime() === date2.getTime();
|
|
68
|
+
}
|
|
69
|
+
if (actual.getTime() !== expected.getTime()) return false;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
if (xor(isObjectLike(actual), isObjectLike(expected))) return false;
|
|
73
|
+
if (Array.isArray(actual) || Array.isArray(expected)) {
|
|
74
|
+
if (!(Array.isArray(actual) && Array.isArray(expected))) return false;
|
|
75
|
+
if (actual.length !== expected.length && !partial) result = false;
|
|
76
|
+
if (partial && actual.length < expected.length) result = false;
|
|
77
|
+
for (const [index, value] of actual.entries()) {
|
|
78
|
+
if (index >= expected.length) continue;
|
|
79
|
+
const expectedValue = expected[index];
|
|
80
|
+
if (mutate && isEvaluation(expectedValue)) {
|
|
81
|
+
const matchesEvaluation = expectedValue(value);
|
|
82
|
+
if (matchesEvaluation) expected[index] = value;
|
|
83
|
+
result && (result = matchesEvaluation);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
result && (result = match$1(value, expectedValue, {
|
|
87
|
+
mutate,
|
|
88
|
+
partial
|
|
89
|
+
}));
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
if (Object.keys(actual).length !== Object.keys(expected).length && !partial) result = false;
|
|
95
|
+
if (globalThis.Buffer && actual instanceof globalThis.Buffer && expected instanceof globalThis.Buffer) return Buffer.compare(actual, expected) === 0;
|
|
96
|
+
for (const key in expected) if (!(key in actual)) {
|
|
97
|
+
result && (result = false);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
for (const index in actual) {
|
|
101
|
+
const expectedValue = expected[index];
|
|
102
|
+
const actualValue = actual[index];
|
|
103
|
+
if (!(index in expected)) {
|
|
104
|
+
if (partial) continue;
|
|
105
|
+
result && (result = false);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (isEvaluation(expectedValue)) {
|
|
109
|
+
if (!expectedValue(actualValue)) {
|
|
110
|
+
result && (result = false);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (mutate) expected[index] = actualValue;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (!match$1(actual[index], expectedValue, {
|
|
117
|
+
mutate,
|
|
118
|
+
partial
|
|
119
|
+
})) result = false;
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/assert/deep-equal.ts
|
|
126
|
+
const [deepEqual, notDeepEqual] = createAssertion({
|
|
127
|
+
messages: {
|
|
128
|
+
notEql: "Expected {{= it.actual }} to deep equal {{= it.expected }}",
|
|
129
|
+
not: "Expected {{= it.actual }} to not deep equal {{= it.expected }}"
|
|
130
|
+
},
|
|
131
|
+
test: (report) => (actual, expected, partialOrMessage = false, message) => {
|
|
132
|
+
const partial = typeof partialOrMessage === "boolean" ? partialOrMessage : false;
|
|
133
|
+
message = typeof partialOrMessage === "string" ? partialOrMessage : message;
|
|
134
|
+
if (typeof expected !== "function") expected = cloneDeep(expected);
|
|
135
|
+
if (match$1(actual, expected, {
|
|
136
|
+
mutate: true,
|
|
137
|
+
partial
|
|
138
|
+
})) return report({
|
|
139
|
+
message,
|
|
140
|
+
status: "ok",
|
|
141
|
+
expected,
|
|
142
|
+
actual
|
|
143
|
+
});
|
|
144
|
+
return report({
|
|
145
|
+
message,
|
|
146
|
+
status: "notok",
|
|
147
|
+
messageId: "notEql",
|
|
148
|
+
expected,
|
|
149
|
+
actual
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/assert/equal.ts
|
|
156
|
+
const [equal, notEqual] = createAssertion({
|
|
157
|
+
messages: {
|
|
158
|
+
equal: "Expected {{= it.actual }} to equal {{= it.expected }}",
|
|
159
|
+
not: "Expected {{= it.actual }} to not equal {{= it.expected }}"
|
|
160
|
+
},
|
|
161
|
+
test: (report) => (a, b, message) => {
|
|
162
|
+
if (Number.isNaN(a) && Number.isNaN(b)) return report({
|
|
163
|
+
status: "ok",
|
|
164
|
+
expected: b,
|
|
165
|
+
actual: a,
|
|
166
|
+
message
|
|
167
|
+
});
|
|
168
|
+
if (a !== b) return report({
|
|
169
|
+
status: "notok",
|
|
170
|
+
messageId: "equal",
|
|
171
|
+
actual: a,
|
|
172
|
+
expected: b,
|
|
173
|
+
message
|
|
174
|
+
});
|
|
175
|
+
return report({
|
|
176
|
+
status: "ok",
|
|
177
|
+
expected: a,
|
|
178
|
+
actual: b,
|
|
179
|
+
message
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/utils/get-type.ts
|
|
186
|
+
const getType = (value) => {
|
|
187
|
+
if (value !== value) return "NaN";
|
|
188
|
+
if (Array.isArray(value)) return "array";
|
|
189
|
+
if (value === null) return "null";
|
|
190
|
+
return typeof value;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/utils/validate-numeric-and-dates.ts
|
|
195
|
+
const allowedTypes = [
|
|
196
|
+
"number",
|
|
197
|
+
"bigint",
|
|
198
|
+
"date"
|
|
199
|
+
];
|
|
200
|
+
const validateNumericsAndDates = (actual, expected) => {
|
|
201
|
+
const actualType = actual instanceof Date ? "date" : getType(actual);
|
|
202
|
+
const expectedType = expected instanceof Date ? "date" : getType(expected);
|
|
203
|
+
if (!allowedTypes.includes(actualType) || !allowedTypes.includes(expectedType)) throw new AssertionError(actualType, expectedType, `Expected arguments to be ${allowedTypes.join("/")}, received ${actualType}/${expectedType}`);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/assert/greater-than.ts
|
|
208
|
+
const [greaterThan, notGreaterThan] = createAssertion({
|
|
209
|
+
messages: {
|
|
210
|
+
smaller: "Expected {{= it.actual }} to be greater than {{= it.expected }}",
|
|
211
|
+
not: "Expected {{= it.actual }} to not be greater than {{= it.expected }}"
|
|
212
|
+
},
|
|
213
|
+
test: (report) => (actual, expected) => {
|
|
214
|
+
validateNumericsAndDates(actual, expected);
|
|
215
|
+
if (actual > expected) return report({
|
|
216
|
+
status: "ok",
|
|
217
|
+
messageId: "not",
|
|
218
|
+
expected,
|
|
219
|
+
actual
|
|
220
|
+
});
|
|
221
|
+
return report({
|
|
222
|
+
status: "notok",
|
|
223
|
+
messageId: "smaller",
|
|
224
|
+
actual,
|
|
225
|
+
expected,
|
|
226
|
+
noStringify: true
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/assert/greater-than-equal.ts
|
|
233
|
+
const [greaterThanEqual, notGreaterThanEqual] = createAssertion({
|
|
234
|
+
messages: {
|
|
235
|
+
notGreaterThanEqual: "Expected {{= it.actual }} to not be greater than or equal to {{= it.expected }}",
|
|
236
|
+
not: "Expected {{= it.actual }} to not be greater than or equal to {{= it.expected }}"
|
|
237
|
+
},
|
|
238
|
+
test: (report) => (a, b, message) => {
|
|
239
|
+
validateNumericsAndDates(a, b);
|
|
240
|
+
if (a < b) return report({
|
|
241
|
+
status: "notok",
|
|
242
|
+
messageId: "notGreaterThanEqual",
|
|
243
|
+
actual: a,
|
|
244
|
+
expected: b,
|
|
245
|
+
message
|
|
246
|
+
});
|
|
247
|
+
return report({
|
|
248
|
+
status: "ok",
|
|
249
|
+
expected: a,
|
|
250
|
+
actual: b
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/assert/has-property.ts
|
|
257
|
+
const [hasProperty, notHasProperty] = createAssertion({
|
|
258
|
+
messages: {
|
|
259
|
+
noProperty: "Expected {{= it.actual }} to have property {{= it.expected }}",
|
|
260
|
+
wrongValue: "Expected {{= it.obj }} to have property {{= it.expected }} with value {{= it.value }}",
|
|
261
|
+
not: "Expected {{= it.actual }} to not have property {{= it.expected }}",
|
|
262
|
+
notWrongValue: "Expected {{= it.obj }} to not have property {{= it.expected }} with value {{= it.value }}"
|
|
263
|
+
},
|
|
264
|
+
test: (report) => (...args) => {
|
|
265
|
+
const [actual, expected, value] = args;
|
|
266
|
+
const actualStringified = stringify(actual);
|
|
267
|
+
if (expected in actual) {
|
|
268
|
+
if (args.length === 3) {
|
|
269
|
+
if (actual[expected] === value) return report({
|
|
270
|
+
status: "ok",
|
|
271
|
+
messageId: "notWrongValue",
|
|
272
|
+
expected,
|
|
273
|
+
actual: actualStringified,
|
|
274
|
+
data: {
|
|
275
|
+
value,
|
|
276
|
+
expected,
|
|
277
|
+
obj: actual
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return report({
|
|
281
|
+
status: "notok",
|
|
282
|
+
messageId: "wrongValue",
|
|
283
|
+
expected,
|
|
284
|
+
actual: actualStringified,
|
|
285
|
+
data: {
|
|
286
|
+
value,
|
|
287
|
+
obj: actualStringified
|
|
288
|
+
},
|
|
289
|
+
noStringify: true
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return report({
|
|
293
|
+
status: "ok",
|
|
294
|
+
noStringify: true,
|
|
295
|
+
expected,
|
|
296
|
+
actual: actualStringified
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
return report({
|
|
300
|
+
status: "notok",
|
|
301
|
+
messageId: "noProperty",
|
|
302
|
+
expected,
|
|
303
|
+
actual: actualStringified,
|
|
304
|
+
noStringify: true
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/assert/has-size.ts
|
|
311
|
+
const [hasSize, notHasSize] = createAssertion({
|
|
312
|
+
messages: {
|
|
313
|
+
array: "Expected array to have length of {{= it.expected }}",
|
|
314
|
+
object: "Expected object to have size of {{= it.expected }}",
|
|
315
|
+
map: "Expected Map to have size of {{= it.expected }}",
|
|
316
|
+
set: "Expected Set to have size of {{= it.expected }}",
|
|
317
|
+
string: "Expected string to have length of {{= it.expected }}",
|
|
318
|
+
not: "Expected array to not have length of {{= it.expected }}",
|
|
319
|
+
notObject: "Expected object to not have size of {{= it.expected }}",
|
|
320
|
+
notMap: "Expected Map to not have size of {{= it.expected }}",
|
|
321
|
+
notSet: "Expected Set to not have size of {{= it.expected }}",
|
|
322
|
+
notString: "Expected string to not have length of {{= it.expected }}",
|
|
323
|
+
invalidValue: "Expected {{= it.actual }} to be an array, object, Map, Set or string"
|
|
324
|
+
},
|
|
325
|
+
test: (report) => (actual, expected, message) => {
|
|
326
|
+
if (Array.isArray(actual)) {
|
|
327
|
+
if (actual.length === expected) return report({
|
|
328
|
+
message,
|
|
329
|
+
status: "ok",
|
|
330
|
+
expected,
|
|
331
|
+
actual: actual.length
|
|
332
|
+
});
|
|
333
|
+
return report({
|
|
334
|
+
message,
|
|
335
|
+
status: "notok",
|
|
336
|
+
messageId: "array",
|
|
337
|
+
expected,
|
|
338
|
+
actual: actual.length
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
if (isPlainObject(actual)) {
|
|
342
|
+
if (Object.keys(actual).length === expected) return report({
|
|
343
|
+
message,
|
|
344
|
+
status: "ok",
|
|
345
|
+
messageId: "notObject",
|
|
346
|
+
expected,
|
|
347
|
+
actual: Object.keys(actual).length
|
|
348
|
+
});
|
|
349
|
+
return report({
|
|
350
|
+
message,
|
|
351
|
+
status: "notok",
|
|
352
|
+
messageId: "object",
|
|
353
|
+
expected,
|
|
354
|
+
actual: Object.keys(actual).length
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
if (actual instanceof Map) {
|
|
358
|
+
if (actual.size === expected) return report({
|
|
359
|
+
message,
|
|
360
|
+
status: "ok",
|
|
361
|
+
messageId: "notMap",
|
|
362
|
+
expected,
|
|
363
|
+
actual: actual.size
|
|
364
|
+
});
|
|
365
|
+
return report({
|
|
366
|
+
message,
|
|
367
|
+
status: "notok",
|
|
368
|
+
messageId: "map",
|
|
369
|
+
expected,
|
|
370
|
+
actual: actual.size
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (actual instanceof Set) {
|
|
374
|
+
if (actual.size === expected) return report({
|
|
375
|
+
message,
|
|
376
|
+
status: "ok",
|
|
377
|
+
messageId: "notSet",
|
|
378
|
+
expected,
|
|
379
|
+
actual: actual.size
|
|
380
|
+
});
|
|
381
|
+
return report({
|
|
382
|
+
message,
|
|
383
|
+
status: "notok",
|
|
384
|
+
messageId: "set",
|
|
385
|
+
expected,
|
|
386
|
+
actual: actual.size
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
if (typeof actual === "string") {
|
|
390
|
+
if (actual.length === expected) return report({
|
|
391
|
+
message,
|
|
392
|
+
status: "ok",
|
|
393
|
+
messageId: "notString",
|
|
394
|
+
expected,
|
|
395
|
+
actual: actual.length
|
|
396
|
+
});
|
|
397
|
+
return report({
|
|
398
|
+
message,
|
|
399
|
+
status: "notok",
|
|
400
|
+
messageId: "string",
|
|
401
|
+
expected,
|
|
402
|
+
actual: actual.length
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
report({
|
|
406
|
+
message,
|
|
407
|
+
status: "notok",
|
|
408
|
+
messageId: "invalidValue",
|
|
409
|
+
actual: typeof actual,
|
|
410
|
+
noStringify: true
|
|
411
|
+
});
|
|
412
|
+
report({
|
|
413
|
+
message,
|
|
414
|
+
status: "ok",
|
|
415
|
+
messageId: "invalidValue",
|
|
416
|
+
actual: typeof actual,
|
|
417
|
+
noStringify: true
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/assert/includes.ts
|
|
424
|
+
const [includes, notIncludes] = createAssertion({
|
|
425
|
+
messages: {
|
|
426
|
+
arrayMisses: "Expected {{= it.actual }} to include {{= it.expected }}",
|
|
427
|
+
not: "Expected {{= it.actual }} to not include {{= it.expected }}"
|
|
428
|
+
},
|
|
429
|
+
test: (report) => (actual, ...elements) => {
|
|
430
|
+
for (const element of elements) if (actual.includes(element)) report({
|
|
431
|
+
messageId: "not",
|
|
432
|
+
status: "ok",
|
|
433
|
+
actual,
|
|
434
|
+
expected: element
|
|
435
|
+
});
|
|
436
|
+
else report({
|
|
437
|
+
messageId: "arrayMisses",
|
|
438
|
+
status: "notok",
|
|
439
|
+
actual,
|
|
440
|
+
expected: element
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/assert/instance-of.ts
|
|
447
|
+
const [instanceOf, notInstanceOf] = createAssertion({
|
|
448
|
+
messages: {
|
|
449
|
+
notInstanceOf: "Expected {{= it.actual }} to be an instance of {{= it.expected }}",
|
|
450
|
+
not: "Expected {{= it.actual }} to not be an instance of {{= it.expected }}"
|
|
451
|
+
},
|
|
452
|
+
test: (report) => (actual, expected) => {
|
|
453
|
+
if (!isObjectLike(actual)) throw new AssertionError(getType(actual), "object", "Expected value to be an object");
|
|
454
|
+
if (!(actual instanceof expected)) return report({
|
|
455
|
+
status: "notok",
|
|
456
|
+
messageId: "notInstanceOf",
|
|
457
|
+
expected: expected.name,
|
|
458
|
+
actual: actual.constructor.name,
|
|
459
|
+
noStringify: true
|
|
460
|
+
});
|
|
461
|
+
return report({
|
|
462
|
+
status: "ok",
|
|
463
|
+
expected: expected.name,
|
|
464
|
+
actual: actual.constructor.name,
|
|
465
|
+
messageId: "not",
|
|
466
|
+
noStringify: true
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/assert/is-empty.ts
|
|
473
|
+
const [isEmpty, notIsEmpty] = createAssertion({
|
|
474
|
+
messages: {
|
|
475
|
+
array: "Expected array to be empty",
|
|
476
|
+
object: "Expected object to be empty",
|
|
477
|
+
map: "Expected Map to be empty",
|
|
478
|
+
set: "Expected Set to be empty",
|
|
479
|
+
not: "Expected array to not be empty",
|
|
480
|
+
notObject: "Expected object to not be empty",
|
|
481
|
+
notMap: "Expected Map to not be empty",
|
|
482
|
+
notSet: "Expected Set to not be empty",
|
|
483
|
+
invalidArgument: "Expected {{= it.actual }} to be an array, object, Map, or Set"
|
|
484
|
+
},
|
|
485
|
+
test: (report) => (actual, message) => {
|
|
486
|
+
if (Array.isArray(actual)) {
|
|
487
|
+
if (actual.length === 0) return report({
|
|
488
|
+
message,
|
|
489
|
+
status: "ok",
|
|
490
|
+
actual,
|
|
491
|
+
expected: []
|
|
492
|
+
});
|
|
493
|
+
return report({
|
|
494
|
+
message,
|
|
495
|
+
status: "notok",
|
|
496
|
+
messageId: "array",
|
|
497
|
+
actual,
|
|
498
|
+
expected: []
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
if (isPlainObject(actual)) {
|
|
502
|
+
if (Object.keys(actual).length === 0) return report({
|
|
503
|
+
message,
|
|
504
|
+
status: "ok",
|
|
505
|
+
messageId: "notObject",
|
|
506
|
+
actual
|
|
507
|
+
});
|
|
508
|
+
return report({
|
|
509
|
+
message,
|
|
510
|
+
status: "notok",
|
|
511
|
+
messageId: "object",
|
|
512
|
+
actual,
|
|
513
|
+
expected: {}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
if (actual instanceof Map) {
|
|
517
|
+
if (actual.size === 0) return report({
|
|
518
|
+
message,
|
|
519
|
+
status: "ok",
|
|
520
|
+
messageId: "notMap",
|
|
521
|
+
actual
|
|
522
|
+
});
|
|
523
|
+
return report({
|
|
524
|
+
message,
|
|
525
|
+
status: "notok",
|
|
526
|
+
messageId: "map",
|
|
527
|
+
actual,
|
|
528
|
+
expected: /* @__PURE__ */ new Map()
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
if (actual instanceof Set) {
|
|
532
|
+
if (actual.size === 0) return report({
|
|
533
|
+
message,
|
|
534
|
+
status: "ok",
|
|
535
|
+
messageId: "notSet",
|
|
536
|
+
actual
|
|
537
|
+
});
|
|
538
|
+
return report({
|
|
539
|
+
message,
|
|
540
|
+
status: "notok",
|
|
541
|
+
messageId: "set",
|
|
542
|
+
actual
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
report({
|
|
546
|
+
message,
|
|
547
|
+
status: "notok",
|
|
548
|
+
messageId: "invalidArgument",
|
|
549
|
+
actual
|
|
550
|
+
});
|
|
551
|
+
report({
|
|
552
|
+
message,
|
|
553
|
+
status: "ok",
|
|
554
|
+
messageId: "invalidArgument",
|
|
555
|
+
actual
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/assert/is-type.ts
|
|
562
|
+
const [isType, notIsType] = createAssertion({
|
|
563
|
+
messages: {
|
|
564
|
+
wrongType: "Expected {{= it.actual }} to be a(n) {{= it.expected }}",
|
|
565
|
+
not: `Expected {{= it.actual }} to not be a(n) {{= it.expected }}`
|
|
566
|
+
},
|
|
567
|
+
test: (report) => (value, expectedType) => {
|
|
568
|
+
const actualType = getType(value);
|
|
569
|
+
if (actualType !== expectedType) return report({
|
|
570
|
+
status: "notok",
|
|
571
|
+
messageId: "wrongType",
|
|
572
|
+
actual: actualType,
|
|
573
|
+
expected: expectedType,
|
|
574
|
+
noStringify: true
|
|
575
|
+
});
|
|
576
|
+
return report({
|
|
577
|
+
status: "ok",
|
|
578
|
+
messageId: "not",
|
|
579
|
+
actual: actualType,
|
|
580
|
+
expected: expectedType,
|
|
581
|
+
noStringify: true
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region src/assert/less-than.ts
|
|
588
|
+
const [lessThan, notLessThan] = createAssertion({
|
|
589
|
+
messages: {
|
|
590
|
+
lesserThan: "Expected {{= it.actual }} to be less than {{= it.expected }}",
|
|
591
|
+
not: "Expected {{= it.actual }} to not be less than {{= it.expected }}"
|
|
592
|
+
},
|
|
593
|
+
test: (report) => (actual, expected, message) => {
|
|
594
|
+
validateNumericsAndDates(actual, expected);
|
|
595
|
+
if (actual >= expected) return report({
|
|
596
|
+
status: "notok",
|
|
597
|
+
messageId: "lesserThan",
|
|
598
|
+
actual,
|
|
599
|
+
expected,
|
|
600
|
+
message
|
|
601
|
+
});
|
|
602
|
+
return report({
|
|
603
|
+
status: "ok",
|
|
604
|
+
actual,
|
|
605
|
+
expected,
|
|
606
|
+
message,
|
|
607
|
+
messageId: "not"
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region src/assert/less-than-equal.ts
|
|
614
|
+
const [lessThanEqual, notLessThanEqual] = createAssertion({
|
|
615
|
+
messages: {
|
|
616
|
+
lesserThanEqual: "Expected {{= it.actual }} to be less than or equal to {{= it.expected }}",
|
|
617
|
+
not: "Expected {{= it.actual }} to not be less than or equal to {{= it.expected }}"
|
|
618
|
+
},
|
|
619
|
+
test: (report) => (actual, expected, message) => {
|
|
620
|
+
validateNumericsAndDates(actual, expected);
|
|
621
|
+
if (actual > expected) return report({
|
|
622
|
+
status: "notok",
|
|
623
|
+
messageId: "lesserThanEqual",
|
|
624
|
+
actual,
|
|
625
|
+
expected,
|
|
626
|
+
message,
|
|
627
|
+
noStringify: true
|
|
628
|
+
});
|
|
629
|
+
return report({
|
|
630
|
+
status: "ok",
|
|
631
|
+
actual,
|
|
632
|
+
expected,
|
|
633
|
+
message,
|
|
634
|
+
messageId: "not",
|
|
635
|
+
noStringify: true
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/assert/match.ts
|
|
642
|
+
const [match, notMatch] = createAssertion({
|
|
643
|
+
messages: {
|
|
644
|
+
noMatch: "Expected {{= it.actual }} to match {{= it.expected }}",
|
|
645
|
+
not: "Expected {{= it.actual }} to not match {{= it.expected }}"
|
|
646
|
+
},
|
|
647
|
+
test: (report) => (actual, regex) => {
|
|
648
|
+
if (!regex.test(actual)) return report({
|
|
649
|
+
messageId: "noMatch",
|
|
650
|
+
status: "notok",
|
|
651
|
+
actual,
|
|
652
|
+
noStringify: true,
|
|
653
|
+
expected: regex.toString()
|
|
654
|
+
});
|
|
655
|
+
report({
|
|
656
|
+
status: "ok",
|
|
657
|
+
actual,
|
|
658
|
+
expected: regex.toString(),
|
|
659
|
+
noStringify: true
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region src/utils/process-error.ts
|
|
666
|
+
const isConstructor = (value) => {
|
|
667
|
+
return typeof value === "function" && value.prototype && value.prototype.isPrototypeOf;
|
|
668
|
+
};
|
|
669
|
+
const processError = (report, error, narrowerOrMessage, message) => {
|
|
670
|
+
message = (typeof narrowerOrMessage === "string" ? narrowerOrMessage : message) ?? null;
|
|
671
|
+
if (!(error instanceof Error)) return report({
|
|
672
|
+
noStringify: true,
|
|
673
|
+
status: "notok",
|
|
674
|
+
messageId: "nonError",
|
|
675
|
+
actual: typeof error,
|
|
676
|
+
expected: "Error"
|
|
677
|
+
});
|
|
678
|
+
if (narrowerOrMessage) {
|
|
679
|
+
if (isConstructor(narrowerOrMessage)) {
|
|
680
|
+
if (!(error instanceof narrowerOrMessage)) return report({
|
|
681
|
+
noStringify: true,
|
|
682
|
+
status: "notok",
|
|
683
|
+
messageId: "invalidConstructor",
|
|
684
|
+
actual: error.name,
|
|
685
|
+
expected: narrowerOrMessage.name,
|
|
686
|
+
message
|
|
687
|
+
});
|
|
688
|
+
return report({
|
|
689
|
+
noStringify: true,
|
|
690
|
+
status: "ok",
|
|
691
|
+
messageId: "notConstructor",
|
|
692
|
+
actual: error.name,
|
|
693
|
+
expected: narrowerOrMessage.name,
|
|
694
|
+
message
|
|
695
|
+
});
|
|
696
|
+
} else if (typeof narrowerOrMessage === "function") {
|
|
697
|
+
if (!narrowerOrMessage(error)) return report({
|
|
698
|
+
noStringify: true,
|
|
699
|
+
status: "notok",
|
|
700
|
+
messageId: "predicate",
|
|
701
|
+
actual: error,
|
|
702
|
+
expected: null,
|
|
703
|
+
message
|
|
704
|
+
});
|
|
705
|
+
return report({
|
|
706
|
+
noStringify: true,
|
|
707
|
+
status: "ok",
|
|
708
|
+
messageId: "notPredicate",
|
|
709
|
+
actual: error,
|
|
710
|
+
expected: null,
|
|
711
|
+
message
|
|
712
|
+
});
|
|
713
|
+
} else if (typeof narrowerOrMessage === "string") return report({
|
|
714
|
+
noStringify: true,
|
|
715
|
+
status: "ok",
|
|
716
|
+
messageId: "throws",
|
|
717
|
+
actual: error,
|
|
718
|
+
message: narrowerOrMessage
|
|
719
|
+
});
|
|
720
|
+
else if (narrowerOrMessage instanceof RegExp) {
|
|
721
|
+
if (!narrowerOrMessage.test(error.message)) return report({
|
|
722
|
+
noStringify: true,
|
|
723
|
+
status: "notok",
|
|
724
|
+
messageId: "regex",
|
|
725
|
+
actual: error.message,
|
|
726
|
+
expected: narrowerOrMessage.toString(),
|
|
727
|
+
message
|
|
728
|
+
});
|
|
729
|
+
return report({
|
|
730
|
+
noStringify: true,
|
|
731
|
+
status: "ok",
|
|
732
|
+
messageId: "notRegex",
|
|
733
|
+
actual: error.message,
|
|
734
|
+
expected: narrowerOrMessage.toString(),
|
|
735
|
+
message
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return report({
|
|
740
|
+
noStringify: true,
|
|
741
|
+
status: "ok",
|
|
742
|
+
actual: error,
|
|
743
|
+
message
|
|
744
|
+
});
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
//#endregion
|
|
748
|
+
//#region src/assert/rejects.ts
|
|
749
|
+
const [rejects, notRejects] = createAssertion({
|
|
750
|
+
messages: {
|
|
751
|
+
invalidArgument: "Expected {{= it.actual }} to be a Promise",
|
|
752
|
+
nonError: "Expected Promise to reject with an instance of Error",
|
|
753
|
+
throws: "Expected Promise to reject",
|
|
754
|
+
invalidConstructor: "Expected Promise to reject with {{= it.expected }}",
|
|
755
|
+
predicate: "Expected {{= it.actual }} to match predicate function",
|
|
756
|
+
regex: "Expected Promise to reject with an error matching {{= it.expected }}",
|
|
757
|
+
not: "Expected Promise to not reject",
|
|
758
|
+
notConstructor: "Expected Promise to not reject with a {{= it.expected }}",
|
|
759
|
+
notPredicate: "Expected {{= it.actual }} to not match predicate function",
|
|
760
|
+
notRegex: "Expected Promise to not reject with an error matching {{= it.expected }}"
|
|
761
|
+
},
|
|
762
|
+
test: (report) => async (promise, narrowerOrMessage, message) => {
|
|
763
|
+
if (!promise || typeof promise.then !== "function") {
|
|
764
|
+
report({
|
|
765
|
+
noStringify: true,
|
|
766
|
+
status: "notok",
|
|
767
|
+
messageId: "invalidArgument",
|
|
768
|
+
actual: typeof promise,
|
|
769
|
+
expected: "Promise"
|
|
770
|
+
});
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
try {
|
|
774
|
+
await promise;
|
|
775
|
+
} catch (error) {
|
|
776
|
+
processError(report, error, narrowerOrMessage, message);
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
report({
|
|
780
|
+
noStringify: true,
|
|
781
|
+
status: "notok",
|
|
782
|
+
messageId: "throws",
|
|
783
|
+
message: typeof narrowerOrMessage === "string" ? narrowerOrMessage : message
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
//#endregion
|
|
789
|
+
//#region src/assert/throws.ts
|
|
790
|
+
const messages = {
|
|
791
|
+
nonError: "Expected function to throw an instance of Error",
|
|
792
|
+
throws: "Expected function to throw",
|
|
793
|
+
invalidConstructor: "Expected function to throw {{= it.expected }}",
|
|
794
|
+
predicate: "Expected {{= it.actual }} to match predicate function",
|
|
795
|
+
regex: "Expected function to throw an error matching {{= it.expected }}",
|
|
796
|
+
not: "Expected function to not throw",
|
|
797
|
+
notConstructor: "Expected function to not throw a {{= it.expected }}",
|
|
798
|
+
notPredicate: "Expected function to not throw an error matching the predicate",
|
|
799
|
+
notRegex: "Expected function to not throw an error matching {{= it.expected }}"
|
|
800
|
+
};
|
|
801
|
+
const [throws, notThrows] = createAssertion({
|
|
802
|
+
messages,
|
|
803
|
+
test: (report) => ((callback, narrowerOrMessage, message) => {
|
|
804
|
+
const argumentType = getType(callback);
|
|
805
|
+
if (argumentType !== "function") throw new AssertionError(argumentType, "function", `Expected ${argumentType} to be a function`);
|
|
806
|
+
try {
|
|
807
|
+
callback();
|
|
808
|
+
} catch (error) {
|
|
809
|
+
return processError(report, error, narrowerOrMessage, message);
|
|
810
|
+
}
|
|
811
|
+
return report({
|
|
812
|
+
noStringify: true,
|
|
813
|
+
status: "notok",
|
|
814
|
+
messageId: "throws",
|
|
815
|
+
message: typeof narrowerOrMessage === "string" ? narrowerOrMessage : message
|
|
816
|
+
});
|
|
817
|
+
})
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
//#endregion
|
|
821
|
+
//#region src/assert/deep-has-property.ts
|
|
822
|
+
const [deepHasProperty, deepNotHasProperty] = createAssertion({
|
|
823
|
+
messages: {
|
|
824
|
+
noProperty: "Expected {{= it.actual }} to have property {{= it.expected }}",
|
|
825
|
+
wrongValue: "Expected {{= it.obj }} to have property {{= it.expected }} with value {{= it.value }}",
|
|
826
|
+
not: "Expected {{= it.actual }} to not have property {{= it.expected }}",
|
|
827
|
+
notWrongValue: "Expected {{= it.obj }} to not have property {{= it.expected }} with value {{= it.value }}"
|
|
828
|
+
},
|
|
829
|
+
test: (report) => (...args) => {
|
|
830
|
+
const [actual, expected, value] = args;
|
|
831
|
+
const actualStringified = stringify(actual);
|
|
832
|
+
if (has(actual, expected)) {
|
|
833
|
+
if (args.length === 3) {
|
|
834
|
+
const actualValue = get(actual, expected);
|
|
835
|
+
if (actualValue === value) return report({
|
|
836
|
+
status: "ok",
|
|
837
|
+
messageId: "notWrongValue",
|
|
838
|
+
expected: value,
|
|
839
|
+
actual: actualValue,
|
|
840
|
+
data: {
|
|
841
|
+
value,
|
|
842
|
+
expected,
|
|
843
|
+
obj: actualStringified
|
|
844
|
+
},
|
|
845
|
+
noStringify: true
|
|
846
|
+
});
|
|
847
|
+
return report({
|
|
848
|
+
status: "notok",
|
|
849
|
+
messageId: "wrongValue",
|
|
850
|
+
expected: value,
|
|
851
|
+
actual: actualValue,
|
|
852
|
+
data: {
|
|
853
|
+
value,
|
|
854
|
+
expected,
|
|
855
|
+
obj: actualStringified
|
|
856
|
+
},
|
|
857
|
+
noStringify: true
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
return report({
|
|
861
|
+
status: "ok",
|
|
862
|
+
noStringify: true,
|
|
863
|
+
expected,
|
|
864
|
+
actual: actualStringified
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
return report({
|
|
868
|
+
status: "notok",
|
|
869
|
+
messageId: "noProperty",
|
|
870
|
+
expected,
|
|
871
|
+
actual: actualStringified,
|
|
872
|
+
noStringify: true
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
//#endregion
|
|
878
|
+
//#region src/assert/starts-with.ts
|
|
879
|
+
const [startsWith, notStartsWith] = createAssertion({
|
|
880
|
+
messages: {
|
|
881
|
+
wrongStart: "Expected {{= it.actual }} to start with {{= it.expected }}",
|
|
882
|
+
not: "Expected {{= it.actual }} to not start with {{= it.expected }}"
|
|
883
|
+
},
|
|
884
|
+
test: (report) => (actual, start) => {
|
|
885
|
+
if (actual.startsWith(start)) report({
|
|
886
|
+
messageId: "not",
|
|
887
|
+
status: "ok",
|
|
888
|
+
actual,
|
|
889
|
+
expected: start
|
|
890
|
+
});
|
|
891
|
+
else report({
|
|
892
|
+
messageId: "wrongStart",
|
|
893
|
+
status: "notok",
|
|
894
|
+
actual,
|
|
895
|
+
expected: start
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/assert/ends-with.ts
|
|
902
|
+
const [endsWith, notEndsWith] = createAssertion({
|
|
903
|
+
messages: {
|
|
904
|
+
wrongEnd: "Expected {{= it.actual }} to end with {{= it.expected }}",
|
|
905
|
+
not: "Expected {{= it.actual }} to not end with {{= it.expected }}"
|
|
906
|
+
},
|
|
907
|
+
test: (report) => (actual, end) => {
|
|
908
|
+
if (actual.endsWith(end)) report({
|
|
909
|
+
messageId: "not",
|
|
910
|
+
status: "ok",
|
|
911
|
+
actual,
|
|
912
|
+
expected: end
|
|
913
|
+
});
|
|
914
|
+
else report({
|
|
915
|
+
messageId: "wrongEnd",
|
|
916
|
+
status: "notok",
|
|
917
|
+
actual,
|
|
918
|
+
expected: end
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
//#endregion
|
|
924
|
+
//#region src/assert/is-before.ts
|
|
925
|
+
const [isBefore, notBefore] = createAssertion({
|
|
926
|
+
messages: {
|
|
927
|
+
after: "Expected {{= it.actual }} to be before {{= it.expected }}",
|
|
928
|
+
not: "Expected {{= it.actual }} to not be before {{= it.expected }}"
|
|
929
|
+
},
|
|
930
|
+
test: (report) => (actual, expected) => {
|
|
931
|
+
if (actual >= expected) return report({
|
|
932
|
+
messageId: "after",
|
|
933
|
+
status: "notok",
|
|
934
|
+
actual,
|
|
935
|
+
expected
|
|
936
|
+
});
|
|
937
|
+
return report({
|
|
938
|
+
status: "ok",
|
|
939
|
+
actual,
|
|
940
|
+
expected
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
//#endregion
|
|
946
|
+
//#region src/assert/is-after.ts
|
|
947
|
+
const [isAfter, notAfter] = createAssertion({
|
|
948
|
+
messages: {
|
|
949
|
+
before: "Expected {{= it.actual }} to be after {{= it.expected }}",
|
|
950
|
+
not: "Expected {{= it.actual }} to not be after {{= it.expected }}"
|
|
951
|
+
},
|
|
952
|
+
test: (report) => (actual, expected) => {
|
|
953
|
+
if (actual <= expected) return report({
|
|
954
|
+
messageId: "before",
|
|
955
|
+
status: "notok",
|
|
956
|
+
actual,
|
|
957
|
+
expected
|
|
958
|
+
});
|
|
959
|
+
return report({
|
|
960
|
+
status: "ok",
|
|
961
|
+
actual,
|
|
962
|
+
expected
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
//#endregion
|
|
968
|
+
//#region src/assert/is-between.ts
|
|
969
|
+
const [isBetween, notBetween] = createAssertion({
|
|
970
|
+
messages: {
|
|
971
|
+
notBetween: "Expected {{= it.actual }} to be between {{= it.lesser }} and {{= it.greater }}",
|
|
972
|
+
not: "Expected {{= it.actual }} to not be between {{= it.lesser }} and {{= it.greater }}"
|
|
973
|
+
},
|
|
974
|
+
test: (report) => (actual, start, end, { inclusive = true } = {}) => {
|
|
975
|
+
const [greater, lesser] = end > start ? [end, start] : [start, end];
|
|
976
|
+
const inclusivelyBetween = actual <= greater && actual >= lesser;
|
|
977
|
+
const exclusivelyBetween = actual < greater && actual > lesser;
|
|
978
|
+
if (inclusive && !inclusivelyBetween) return report({
|
|
979
|
+
messageId: "notBetween",
|
|
980
|
+
status: "notok",
|
|
981
|
+
actual,
|
|
982
|
+
data: {
|
|
983
|
+
lesser,
|
|
984
|
+
greater
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
if (!inclusive && !exclusivelyBetween) return report({
|
|
988
|
+
messageId: "notBetween",
|
|
989
|
+
status: "notok",
|
|
990
|
+
actual,
|
|
991
|
+
data: {
|
|
992
|
+
lesser,
|
|
993
|
+
greater
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
return report({
|
|
997
|
+
status: "ok",
|
|
998
|
+
actual,
|
|
999
|
+
data: {
|
|
1000
|
+
lesser,
|
|
1001
|
+
greater
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
//#endregion
|
|
1008
|
+
//#region src/assert/in-ballpark.ts
|
|
1009
|
+
const [inBallpark, notInBallpark] = createAssertion({
|
|
1010
|
+
messages: {
|
|
1011
|
+
miss: "Expected {{= it.actual }} to be in ballpark of {{= it.expected }}",
|
|
1012
|
+
not: "Expected {{= it.actual }} to not be in ballpark of {{= it.expected }}",
|
|
1013
|
+
invalidMultiplier: "Expected multiplier to be between 0 and 1"
|
|
1014
|
+
},
|
|
1015
|
+
test: (report) => (actual, expected, allowedDifference = .1) => {
|
|
1016
|
+
const absActual = Math.abs(actual);
|
|
1017
|
+
const absExpected = Math.abs(expected);
|
|
1018
|
+
if (allowedDifference <= 0 || allowedDifference >= 1) {
|
|
1019
|
+
report({
|
|
1020
|
+
status: "ok",
|
|
1021
|
+
messageId: "invalidMultiplier",
|
|
1022
|
+
actual: allowedDifference
|
|
1023
|
+
});
|
|
1024
|
+
return report({
|
|
1025
|
+
status: "notok",
|
|
1026
|
+
messageId: "invalidMultiplier",
|
|
1027
|
+
actual: allowedDifference
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
if (absActual <= absExpected * (1 + allowedDifference) && absActual >= absExpected * (1 - allowedDifference)) return report({
|
|
1031
|
+
status: "ok",
|
|
1032
|
+
expected,
|
|
1033
|
+
actual
|
|
1034
|
+
});
|
|
1035
|
+
return report({
|
|
1036
|
+
status: "notok",
|
|
1037
|
+
messageId: "miss",
|
|
1038
|
+
expected,
|
|
1039
|
+
actual
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
//#endregion
|
|
1045
|
+
//#region src/assert/round-to.ts
|
|
1046
|
+
const [roundTo, notRoundTo] = createAssertion({
|
|
1047
|
+
messages: {
|
|
1048
|
+
miss: "Expected {{= it.actual }} to round to {{= it.expected }}",
|
|
1049
|
+
tooManyDecimals: "Invalid argument for target, decimals for target ({{= it.expected }}) cannot be less than rounding decimals ({{= it.decimals }})",
|
|
1050
|
+
not: "Expected {{= it.actual }} to not round to {{= it.expected }}"
|
|
1051
|
+
},
|
|
1052
|
+
test: (report) => (actual, expected, decimals = 0) => {
|
|
1053
|
+
var _expected$toString$sp;
|
|
1054
|
+
if (((_expected$toString$sp = expected.toString().split(".")[1]) === null || _expected$toString$sp === void 0 ? void 0 : _expected$toString$sp.length) > decimals) {
|
|
1055
|
+
report({
|
|
1056
|
+
status: "notok",
|
|
1057
|
+
messageId: "tooManyDecimals",
|
|
1058
|
+
expected,
|
|
1059
|
+
actual,
|
|
1060
|
+
data: { decimals },
|
|
1061
|
+
noStringify: true
|
|
1062
|
+
});
|
|
1063
|
+
report({
|
|
1064
|
+
status: "ok",
|
|
1065
|
+
messageId: "tooManyDecimals",
|
|
1066
|
+
expected,
|
|
1067
|
+
actual,
|
|
1068
|
+
data: { decimals },
|
|
1069
|
+
noStringify: true
|
|
1070
|
+
});
|
|
1071
|
+
return true;
|
|
1072
|
+
}
|
|
1073
|
+
if (round(actual, decimals) === expected) return report({
|
|
1074
|
+
status: "ok",
|
|
1075
|
+
expected,
|
|
1076
|
+
actual
|
|
1077
|
+
});
|
|
1078
|
+
return report({
|
|
1079
|
+
status: "notok",
|
|
1080
|
+
messageId: "miss",
|
|
1081
|
+
expected,
|
|
1082
|
+
actual
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
const round = (value, decimals) => {
|
|
1087
|
+
const factor = 10 ** decimals;
|
|
1088
|
+
return Math.round(value * factor) / factor;
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
//#endregion
|
|
1092
|
+
//#region src/assert/has-members.ts
|
|
1093
|
+
const [hasMembers, notHasMembers] = createAssertion({
|
|
1094
|
+
messages: {
|
|
1095
|
+
hasMembers: "Expected {{= it.actual }} to have members {{= it.expected }}",
|
|
1096
|
+
same: "Expected {{= it.actual }} to have same members as {{= it.expected }}",
|
|
1097
|
+
order: "Expected {{= it.actual }} to have ordered members {{= it.expected }}",
|
|
1098
|
+
not: "Expected {{= it.actual }} to not have members {{= it.expected }}",
|
|
1099
|
+
notSame: "Expected {{= it.actual }} to not have same members as {{= it.expected }}"
|
|
1100
|
+
},
|
|
1101
|
+
test: (report) => (actual, expected, { deep = false, partial = false, ordered = false, same = false } = {}, message) => {
|
|
1102
|
+
let lastIndex = -1;
|
|
1103
|
+
for (const item of expected) if (deep || partial) {
|
|
1104
|
+
const actualIndex = actual.findIndex((actualItem, index) => {
|
|
1105
|
+
if (!ordered) return match$1(actualItem, item, { partial });
|
|
1106
|
+
if (lastIndex >= index) return false;
|
|
1107
|
+
return match$1(actualItem, item, { partial });
|
|
1108
|
+
});
|
|
1109
|
+
lastIndex = actualIndex;
|
|
1110
|
+
if (actualIndex === -1) return report({
|
|
1111
|
+
status: "notok",
|
|
1112
|
+
messageId: ordered ? "order" : "hasMembers",
|
|
1113
|
+
actual,
|
|
1114
|
+
expected,
|
|
1115
|
+
message
|
|
1116
|
+
});
|
|
1117
|
+
} else if (actual.includes(item)) {
|
|
1118
|
+
if (ordered && lastIndex >= actual.indexOf(item, lastIndex + 1)) return report({
|
|
1119
|
+
status: "notok",
|
|
1120
|
+
messageId: "order",
|
|
1121
|
+
actual,
|
|
1122
|
+
expected,
|
|
1123
|
+
message
|
|
1124
|
+
});
|
|
1125
|
+
lastIndex = actual.indexOf(item, lastIndex + 1);
|
|
1126
|
+
} else return report({
|
|
1127
|
+
status: "notok",
|
|
1128
|
+
messageId: "hasMembers",
|
|
1129
|
+
actual,
|
|
1130
|
+
expected,
|
|
1131
|
+
message
|
|
1132
|
+
});
|
|
1133
|
+
if (same && actual.length !== expected.length) return report({
|
|
1134
|
+
status: "notok",
|
|
1135
|
+
messageId: "same",
|
|
1136
|
+
actual,
|
|
1137
|
+
expected,
|
|
1138
|
+
message
|
|
1139
|
+
});
|
|
1140
|
+
return report({
|
|
1141
|
+
status: "ok",
|
|
1142
|
+
messageId: same ? "notSame" : "not",
|
|
1143
|
+
actual,
|
|
1144
|
+
expected,
|
|
1145
|
+
message
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region src/assert/has-keys.ts
|
|
1152
|
+
const [hasKeys, notHasKeys] = createAssertion({
|
|
1153
|
+
messages: {
|
|
1154
|
+
noKey: "Expected {{= it.object }} to have keys {{= it.expected }}",
|
|
1155
|
+
not: "Expected {{= it.object }} to not have keys {{= it.expected }}"
|
|
1156
|
+
},
|
|
1157
|
+
test: (report) => (object, keys, message) => {
|
|
1158
|
+
const keysArray = castArray(keys);
|
|
1159
|
+
if (object instanceof Map) {
|
|
1160
|
+
for (const key of keysArray) if (!object.has(key)) {
|
|
1161
|
+
report({
|
|
1162
|
+
status: "notok",
|
|
1163
|
+
message,
|
|
1164
|
+
messageId: "noKey",
|
|
1165
|
+
data: { object },
|
|
1166
|
+
actual: [...object.keys()],
|
|
1167
|
+
expected: keysArray
|
|
1168
|
+
});
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
report({
|
|
1172
|
+
status: "ok",
|
|
1173
|
+
data: { object },
|
|
1174
|
+
actual: [...object.keys()],
|
|
1175
|
+
expected: keysArray
|
|
1176
|
+
});
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
for (const key of keysArray) if (!(key in object)) {
|
|
1180
|
+
report({
|
|
1181
|
+
status: "notok",
|
|
1182
|
+
message,
|
|
1183
|
+
messageId: "noKey",
|
|
1184
|
+
data: { object },
|
|
1185
|
+
actual: object,
|
|
1186
|
+
expected: keysArray
|
|
1187
|
+
});
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
report({
|
|
1191
|
+
status: "ok",
|
|
1192
|
+
data: { object },
|
|
1193
|
+
actual: Object.keys(object),
|
|
1194
|
+
expected: keysArray
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
//#endregion
|
|
1200
|
+
//#region src/assert.ts
|
|
1201
|
+
var assert_exports = /* @__PURE__ */ __export({
|
|
1202
|
+
assert: () => assert,
|
|
1203
|
+
deepEqual: () => deepEqual,
|
|
1204
|
+
deepHasProperty: () => deepHasProperty,
|
|
1205
|
+
deepNotHasProperty: () => deepNotHasProperty,
|
|
1206
|
+
endsWith: () => endsWith,
|
|
1207
|
+
equal: () => equal,
|
|
1208
|
+
greaterThan: () => greaterThan,
|
|
1209
|
+
greaterThanEqual: () => greaterThanEqual,
|
|
1210
|
+
hasKeys: () => hasKeys,
|
|
1211
|
+
hasMembers: () => hasMembers,
|
|
1212
|
+
hasProperty: () => hasProperty,
|
|
1213
|
+
hasSize: () => hasSize,
|
|
1214
|
+
inBallpark: () => inBallpark,
|
|
1215
|
+
includes: () => includes,
|
|
1216
|
+
instanceOf: () => instanceOf,
|
|
1217
|
+
isAfter: () => isAfter,
|
|
1218
|
+
isBefore: () => isBefore,
|
|
1219
|
+
isBetween: () => isBetween,
|
|
1220
|
+
isEmpty: () => isEmpty,
|
|
1221
|
+
isType: () => isType,
|
|
1222
|
+
lessThan: () => lessThan,
|
|
1223
|
+
lessThanEqual: () => lessThanEqual,
|
|
1224
|
+
match: () => match,
|
|
1225
|
+
notAfter: () => notAfter,
|
|
1226
|
+
notBefore: () => notBefore,
|
|
1227
|
+
notBetween: () => notBetween,
|
|
1228
|
+
notDeepEqual: () => notDeepEqual,
|
|
1229
|
+
notEndsWith: () => notEndsWith,
|
|
1230
|
+
notEqual: () => notEqual,
|
|
1231
|
+
notGreaterThan: () => notGreaterThan,
|
|
1232
|
+
notGreaterThanEqual: () => notGreaterThanEqual,
|
|
1233
|
+
notHasKeys: () => notHasKeys,
|
|
1234
|
+
notHasMembers: () => notHasMembers,
|
|
1235
|
+
notHasProperty: () => notHasProperty,
|
|
1236
|
+
notHasSize: () => notHasSize,
|
|
1237
|
+
notInBallpark: () => notInBallpark,
|
|
1238
|
+
notIncludes: () => notIncludes,
|
|
1239
|
+
notInstanceOf: () => notInstanceOf,
|
|
1240
|
+
notIsEmpty: () => notIsEmpty,
|
|
1241
|
+
notIsType: () => notIsType,
|
|
1242
|
+
notLessThan: () => notLessThan,
|
|
1243
|
+
notLessThanEqual: () => notLessThanEqual,
|
|
1244
|
+
notMatch: () => notMatch,
|
|
1245
|
+
notRejects: () => notRejects,
|
|
1246
|
+
notRoundTo: () => notRoundTo,
|
|
1247
|
+
notStartsWith: () => notStartsWith,
|
|
1248
|
+
notThrows: () => notThrows,
|
|
1249
|
+
rejects: () => rejects,
|
|
1250
|
+
roundTo: () => roundTo,
|
|
1251
|
+
startsWith: () => startsWith,
|
|
1252
|
+
throws: () => throws
|
|
1253
|
+
});
|
|
1254
|
+
const assert = () => {
|
|
1255
|
+
throw new Error("Not implemented");
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
//#endregion
|
|
1259
|
+
export { any, assert, assert_exports, createEvaluation, deepEqual, deepHasProperty, deepNotHasProperty, endsWith, equal, greaterThan, greaterThanEqual, hasKeys, hasMembers, hasProperty, hasSize, inBallpark, includes, instanceOf, isAfter, isBefore, isBetween, isEmpty, isType, lessThan, lessThanEqual, match, notAfter, notBefore, notBetween, notDeepEqual, notEndsWith, notEqual, notGreaterThan, notGreaterThanEqual, notHasKeys, notHasMembers, notHasProperty, notHasSize, notInBallpark, notIncludes, notInstanceOf, notIsEmpty, notIsType, notLessThan, notLessThanEqual, notMatch, notRejects, notRoundTo, notStartsWith, notThrows, rejects, roundTo, startsWith, throws };
|
|
1260
|
+
//# sourceMappingURL=assert-kFXp7i_B.js.map
|