@plugjs/expect5 0.4.4 → 0.4.5
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 +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/execution/executor.cjs.map +1 -1
- package/dist/execution/executor.d.ts +1 -1
- package/dist/execution/executor.mjs +1 -1
- package/dist/execution/executor.mjs.map +1 -1
- package/dist/execution/setup.cjs.map +1 -1
- package/dist/execution/setup.d.ts +1 -1
- package/dist/execution/setup.mjs +1 -1
- package/dist/execution/setup.mjs.map +1 -1
- package/dist/expectation/async.cjs +58 -45
- package/dist/expectation/async.cjs.map +1 -1
- package/dist/expectation/async.d.ts +53 -52
- package/dist/expectation/async.mjs +59 -42
- package/dist/expectation/async.mjs.map +1 -1
- package/dist/expectation/diff.cjs.map +1 -1
- package/dist/expectation/diff.mjs +6 -1
- package/dist/expectation/diff.mjs.map +1 -1
- package/dist/expectation/expect.cjs +11 -165
- package/dist/expectation/expect.cjs.map +2 -2
- package/dist/expectation/expect.d.ts +10 -112
- package/dist/expectation/expect.mjs +12 -207
- package/dist/expectation/expect.mjs.map +2 -2
- package/dist/expectation/expectations.cjs +549 -0
- package/dist/expectation/expectations.cjs.map +6 -0
- package/dist/expectation/expectations.d.ts +454 -0
- package/dist/expectation/expectations.mjs +530 -0
- package/dist/expectation/expectations.mjs.map +6 -0
- package/dist/expectation/include.cjs +43 -41
- package/dist/expectation/include.cjs.map +1 -1
- package/dist/expectation/include.d.ts +3 -19
- package/dist/expectation/include.mjs +43 -41
- package/dist/expectation/include.mjs.map +1 -1
- package/dist/expectation/matchers.cjs +350 -0
- package/dist/expectation/matchers.cjs.map +6 -0
- package/dist/expectation/matchers.d.ts +375 -0
- package/dist/expectation/matchers.mjs +328 -0
- package/dist/expectation/matchers.mjs.map +6 -0
- package/dist/expectation/print.cjs.map +1 -1
- package/dist/expectation/print.d.ts +2 -2
- package/dist/expectation/print.mjs.map +1 -1
- package/dist/expectation/types.cjs +17 -23
- package/dist/expectation/types.cjs.map +1 -1
- package/dist/expectation/types.d.ts +7 -51
- package/dist/expectation/types.mjs +17 -22
- package/dist/expectation/types.mjs.map +1 -1
- package/dist/globals.d.ts +2 -2
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +11 -12
- package/dist/index.mjs.map +1 -1
- package/dist/test.cjs +34 -5
- package/dist/test.cjs.map +1 -1
- package/dist/test.d.ts +2 -2
- package/dist/test.mjs +35 -6
- package/dist/test.mjs.map +1 -1
- package/package.json +2 -2
- package/src/cli.mts +1 -1
- package/src/execution/executor.ts +1 -3
- package/src/execution/setup.ts +1 -3
- package/src/expectation/async.ts +116 -145
- package/src/expectation/diff.ts +7 -3
- package/src/expectation/expect.ts +22 -362
- package/src/expectation/expectations.ts +971 -0
- package/src/expectation/include.ts +59 -75
- package/src/expectation/matchers.ts +698 -0
- package/src/expectation/print.ts +8 -4
- package/src/expectation/types.ts +22 -94
- package/src/globals.ts +2 -2
- package/src/index.ts +17 -10
- package/src/test.ts +34 -10
- package/dist/expectation/basic.cjs +0 -188
- package/dist/expectation/basic.cjs.map +0 -6
- package/dist/expectation/basic.d.ts +0 -90
- package/dist/expectation/basic.mjs +0 -156
- package/dist/expectation/basic.mjs.map +0 -6
- package/dist/expectation/throwing.cjs +0 -58
- package/dist/expectation/throwing.cjs.map +0 -6
- package/dist/expectation/throwing.d.ts +0 -36
- package/dist/expectation/throwing.mjs +0 -32
- package/dist/expectation/throwing.mjs.map +0 -6
- package/dist/expectation/trivial.cjs +0 -96
- package/dist/expectation/trivial.cjs.map +0 -6
- package/dist/expectation/trivial.d.ts +0 -13
- package/dist/expectation/trivial.mjs +0 -61
- package/dist/expectation/trivial.mjs.map +0 -6
- package/src/expectation/basic.ts +0 -413
- package/src/expectation/throwing.ts +0 -106
- package/src/expectation/trivial.ts +0 -107
|
@@ -24,172 +24,18 @@ __export(expect_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(expect_exports);
|
|
26
26
|
var import_async = require("./async.cjs");
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
var syncExpectations = {
|
|
38
|
-
// basic
|
|
39
|
-
toBeA: import_basic.toBeA,
|
|
40
|
-
toBeCloseTo: import_basic.toBeCloseTo,
|
|
41
|
-
toBeError: import_basic.toBeError,
|
|
42
|
-
toBeGreaterThan: import_basic.toBeGreaterThan,
|
|
43
|
-
toBeGreaterThanOrEqual: import_basic.toBeGreaterThanOrEqual,
|
|
44
|
-
toBeInstanceOf: import_basic.toBeInstanceOf,
|
|
45
|
-
toBeLessThan: import_basic.toBeLessThan,
|
|
46
|
-
toBeLessThanOrEqual: import_basic.toBeLessThanOrEqual,
|
|
47
|
-
toBeWithinRange: import_basic.toBeWithinRange,
|
|
48
|
-
toEqual: import_basic.toEqual,
|
|
49
|
-
toHaveLength: import_basic.toHaveLength,
|
|
50
|
-
toHaveProperty: import_basic.toHaveProperty,
|
|
51
|
-
toHaveSize: import_basic.toHaveSize,
|
|
52
|
-
toMatch: import_basic.toMatch,
|
|
53
|
-
toStrictlyEqual: import_basic.toStrictlyEqual,
|
|
54
|
-
// include
|
|
55
|
-
toInclude: import_include.toInclude,
|
|
56
|
-
toMatchContents: import_include.toMatchContents,
|
|
57
|
-
// throwing
|
|
58
|
-
toThrow: import_throwing.toThrow,
|
|
59
|
-
toThrowError: import_throwing.toThrowError,
|
|
60
|
-
// trivial
|
|
61
|
-
toBeDefined: import_trivial.toBeDefined,
|
|
62
|
-
toBeFalse: import_trivial.toBeFalse,
|
|
63
|
-
toBeFalsy: import_trivial.toBeFalsy,
|
|
64
|
-
toBeNaN: import_trivial.toBeNaN,
|
|
65
|
-
toBeNegativeInfinity: import_trivial.toBeNegativeInfinity,
|
|
66
|
-
toBeNull: import_trivial.toBeNull,
|
|
67
|
-
toBeNullable: import_trivial.toBeNullable,
|
|
68
|
-
toBePositiveInfinity: import_trivial.toBePositiveInfinity,
|
|
69
|
-
toBeTrue: import_trivial.toBeTrue,
|
|
70
|
-
toBeTruthy: import_trivial.toBeTruthy,
|
|
71
|
-
toBeUndefined: import_trivial.toBeUndefined
|
|
72
|
-
};
|
|
73
|
-
var allExpectations = {
|
|
74
|
-
...asyncExpectations,
|
|
75
|
-
...syncExpectations
|
|
76
|
-
};
|
|
77
|
-
var ExpectationsContextImpl = class {
|
|
78
|
-
constructor(value, negative, expects, negated, parent) {
|
|
79
|
-
this.value = value;
|
|
80
|
-
this.negative = negative;
|
|
81
|
-
this.expects = expects;
|
|
82
|
-
this.negated = negated;
|
|
83
|
-
this.parent = parent;
|
|
84
|
-
}
|
|
85
|
-
forValue(value) {
|
|
86
|
-
return new ExpectationsImpl(value);
|
|
87
|
-
}
|
|
88
|
-
forProperty(prop) {
|
|
89
|
-
this.expects.toBeDefined();
|
|
90
|
-
const value = this.value[prop];
|
|
91
|
-
const parent = { context: this, prop };
|
|
92
|
-
return new ExpectationsImpl(value, parent);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
var ExpectationsImpl = class {
|
|
96
|
-
_context;
|
|
97
|
-
value;
|
|
98
|
-
not;
|
|
99
|
-
constructor(value, parent, positives) {
|
|
100
|
-
this.value = value;
|
|
101
|
-
if (positives) {
|
|
102
|
-
this.not = positives;
|
|
103
|
-
this._context = new ExpectationsContextImpl(
|
|
104
|
-
value,
|
|
105
|
-
true,
|
|
106
|
-
positives,
|
|
107
|
-
this,
|
|
108
|
-
parent
|
|
109
|
-
);
|
|
110
|
-
} else {
|
|
111
|
-
this._context = new ExpectationsContextImpl(
|
|
112
|
-
value,
|
|
113
|
-
false,
|
|
114
|
-
this,
|
|
115
|
-
this,
|
|
116
|
-
parent
|
|
117
|
-
);
|
|
118
|
-
this.not = new ExpectationsImpl(value, parent, this);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
static {
|
|
122
|
-
for (const [key, value] of Object.entries(allExpectations)) {
|
|
123
|
-
const expectation = value;
|
|
124
|
-
const fn = function(...args) {
|
|
125
|
-
try {
|
|
126
|
-
return expectation.call(this._context, ...args);
|
|
127
|
-
} catch (error) {
|
|
128
|
-
if (error instanceof import_types.ExpectationError)
|
|
129
|
-
Error.captureStackTrace(error, fn);
|
|
130
|
-
throw error;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
Object.defineProperty(fn, "name", { value: key });
|
|
134
|
-
Object.defineProperty(this.prototype, key, { value: fn });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
var MatcherImpl = class {
|
|
139
|
-
_matchers;
|
|
140
|
-
_positiveBuilder;
|
|
141
|
-
_negativeBuilder;
|
|
142
|
-
_negative;
|
|
143
|
-
constructor(_matchers, _positiveBuilder) {
|
|
144
|
-
this._matchers = _matchers;
|
|
145
|
-
if (_positiveBuilder) {
|
|
146
|
-
this._negative = true;
|
|
147
|
-
this._positiveBuilder = _positiveBuilder;
|
|
148
|
-
this._negativeBuilder = this;
|
|
149
|
-
} else {
|
|
150
|
-
this._negative = false;
|
|
151
|
-
this._positiveBuilder = this;
|
|
152
|
-
this._negativeBuilder = new MatcherImpl(this._matchers, this);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
get not() {
|
|
156
|
-
return this._negative ? this._positiveBuilder : this._negativeBuilder;
|
|
157
|
-
}
|
|
158
|
-
expect(value) {
|
|
159
|
-
const expectations = expect(value);
|
|
160
|
-
for (const [expectation, negative, args] of this._matchers) {
|
|
161
|
-
const expect2 = negative ? expectations.not : expectations;
|
|
162
|
-
expect2[expectation](...args);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
static {
|
|
166
|
-
Object.defineProperty(this.prototype, import_types.matcherMarker, { value: import_types.matcherMarker });
|
|
167
|
-
for (const key in syncExpectations) {
|
|
168
|
-
Object.defineProperty(this.prototype, key, {
|
|
169
|
-
value: function(...args) {
|
|
170
|
-
return new MatcherImpl([
|
|
171
|
-
...this._matchers,
|
|
172
|
-
[key, this._negative, args]
|
|
173
|
-
]);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
var expect = (value) => {
|
|
180
|
-
return new ExpectationsImpl(value);
|
|
181
|
-
};
|
|
182
|
-
Object.defineProperty(expect, "not", {
|
|
183
|
-
get: () => new MatcherImpl([]).not
|
|
184
|
-
});
|
|
185
|
-
for (const name in syncExpectations) {
|
|
186
|
-
Object.defineProperty(expect, name, {
|
|
187
|
-
value: function(...args) {
|
|
188
|
-
const builder = new MatcherImpl([]);
|
|
189
|
-
return builder[name](...args);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
27
|
+
var import_matchers = require("./matchers.cjs");
|
|
28
|
+
var expect = (value, remarks) => {
|
|
29
|
+
return new import_async.AsyncExpectations(value, remarks);
|
|
30
|
+
};
|
|
31
|
+
for (const key of Object.getOwnPropertyNames(import_matchers.Matchers.prototype)) {
|
|
32
|
+
if (!key.startsWith("to"))
|
|
33
|
+
continue;
|
|
34
|
+
const matcher = (...args) => new import_matchers.Matchers()[key](...args);
|
|
35
|
+
Object.defineProperty(matcher, "name", { value: key });
|
|
36
|
+
Object.defineProperty(expect, key, { value: matcher });
|
|
192
37
|
}
|
|
38
|
+
Object.defineProperty(expect, "not", { get: () => new import_matchers.Matchers().not });
|
|
193
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
194
40
|
0 && (module.exports = {
|
|
195
41
|
expect
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/expectation/expect.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AAClC,sBAAyB;AAgBlB,IAAM,SAAkB,CAAC,OAAY,YAAqB;AAC/D,SAAO,IAAI,+BAAkB,OAAO,OAAO;AAC7C;AAGA,WAAW,OAAO,OAAO,oBAAoB,yBAAS,SAAS,GAAG;AAChE,MAAI,CAAE,IAAI,WAAW,IAAI;AAAG;AAE5B,QAAM,UAAU,IAAI,SAAuB,IAAI,yBAAS,EAAU,GAAG,EAAE,GAAG,IAAI;AAC9E,SAAO,eAAe,SAAS,QAAQ,EAAE,OAAO,IAAI,CAAC;AACrD,SAAO,eAAe,QAAQ,KAAK,EAAE,OAAO,QAAQ,CAAC;AACvD;AAGA,OAAO,eAAe,QAAQ,OAAO,EAAE,KAAK,MAAM,IAAI,yBAAS,EAAE,IAAI,CAAC;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
|
@@ -1,113 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const asyncExpectations: {
|
|
7
|
-
readonly toBeResolved: typeof toBeResolved;
|
|
8
|
-
readonly toBeRejected: typeof toBeRejected;
|
|
9
|
-
readonly toBeRejectedWithError: typeof toBeRejectedWithError;
|
|
10
|
-
};
|
|
11
|
-
type AsyncExpectations = typeof asyncExpectations;
|
|
12
|
-
declare const syncExpectations: {
|
|
13
|
-
readonly toBeA: typeof toBeA;
|
|
14
|
-
readonly toBeCloseTo: typeof toBeCloseTo;
|
|
15
|
-
readonly toBeError: typeof toBeError;
|
|
16
|
-
readonly toBeGreaterThan: typeof toBeGreaterThan;
|
|
17
|
-
readonly toBeGreaterThanOrEqual: typeof toBeGreaterThanOrEqual;
|
|
18
|
-
readonly toBeInstanceOf: typeof toBeInstanceOf;
|
|
19
|
-
readonly toBeLessThan: typeof toBeLessThan;
|
|
20
|
-
readonly toBeLessThanOrEqual: typeof toBeLessThanOrEqual;
|
|
21
|
-
readonly toBeWithinRange: typeof toBeWithinRange;
|
|
22
|
-
readonly toEqual: typeof toEqual;
|
|
23
|
-
readonly toHaveLength: typeof toHaveLength;
|
|
24
|
-
readonly toHaveProperty: typeof toHaveProperty;
|
|
25
|
-
readonly toHaveSize: typeof toHaveSize;
|
|
26
|
-
readonly toMatch: typeof toMatch;
|
|
27
|
-
readonly toStrictlyEqual: typeof toStrictlyEqual;
|
|
28
|
-
readonly toInclude: typeof toInclude;
|
|
29
|
-
readonly toMatchContents: typeof toMatchContents;
|
|
30
|
-
readonly toThrow: typeof toThrow;
|
|
31
|
-
readonly toThrowError: typeof toThrowError;
|
|
32
|
-
readonly toBeDefined: typeof toBeDefined;
|
|
33
|
-
readonly toBeFalse: typeof toBeFalse;
|
|
34
|
-
readonly toBeFalsy: typeof toBeFalsy;
|
|
35
|
-
readonly toBeNaN: typeof toBeNaN;
|
|
36
|
-
readonly toBeNegativeInfinity: typeof toBeNegativeInfinity;
|
|
37
|
-
readonly toBeNull: typeof toBeNull;
|
|
38
|
-
readonly toBeNullable: typeof toBeNullable;
|
|
39
|
-
readonly toBePositiveInfinity: typeof toBePositiveInfinity;
|
|
40
|
-
readonly toBeTrue: typeof toBeTrue;
|
|
41
|
-
readonly toBeTruthy: typeof toBeTruthy;
|
|
42
|
-
readonly toBeUndefined: typeof toBeUndefined;
|
|
43
|
-
};
|
|
44
|
-
type SyncExpectations = typeof syncExpectations;
|
|
45
|
-
type AllExpectations = SyncExpectations & AsyncExpectations;
|
|
46
|
-
/** Combine the arguments of a number of overloads (tuples) */
|
|
47
|
-
type OverloadArguments<T> = T extends readonly [infer T, ...infer Rest] ? [
|
|
48
|
-
T,
|
|
49
|
-
...OverloadArguments<Rest>
|
|
50
|
-
] : T extends readonly [] ? [] : T extends readonly (infer T)[] ? unknown extends T ? never : T extends undefined ? [] : [
|
|
51
|
-
T
|
|
52
|
-
] : never;
|
|
53
|
-
/**
|
|
54
|
-
* Remap `Functions` (a record of functions) inferring arguments and forcing
|
|
55
|
-
* return type to `Result`
|
|
56
|
-
*/
|
|
57
|
-
type OverloadFunctions<Functions, Result> = {
|
|
58
|
-
[k in keyof Functions]: Functions[k] extends {
|
|
59
|
-
(...args: infer A0): any;
|
|
60
|
-
(...args: infer A1): any;
|
|
61
|
-
(...args: infer A2): any;
|
|
62
|
-
(...args: infer A3): any;
|
|
63
|
-
(...args: infer A4): any;
|
|
64
|
-
(...args: infer A5): any;
|
|
65
|
-
} ? (...args: OverloadArguments<A0 | A1 | A2 | A3 | A4 | A5>) => Result : Functions[k] extends {
|
|
66
|
-
(...args: infer A0): any;
|
|
67
|
-
(...args: infer A1): any;
|
|
68
|
-
(...args: infer A2): any;
|
|
69
|
-
(...args: infer A3): any;
|
|
70
|
-
(...args: infer A4): any;
|
|
71
|
-
} ? (...args: OverloadArguments<A0 | A1 | A2 | A3 | A4>) => Result : Functions[k] extends {
|
|
72
|
-
(...args: infer A0): any;
|
|
73
|
-
(...args: infer A1): any;
|
|
74
|
-
(...args: infer A2): any;
|
|
75
|
-
(...args: infer A3): any;
|
|
76
|
-
} ? (...args: OverloadArguments<A0 | A1 | A2 | A3>) => Result : Functions[k] extends {
|
|
77
|
-
(...args: infer A0): any;
|
|
78
|
-
(...args: infer A1): any;
|
|
79
|
-
(...args: infer A2): any;
|
|
80
|
-
} ? (...args: OverloadArguments<A0 | A1 | A2>) => Result : Functions[k] extends {
|
|
81
|
-
(...args: infer A0): any;
|
|
82
|
-
(...args: infer A1): any;
|
|
83
|
-
} ? (...args: OverloadArguments<A0 | A1>) => Result : Functions[k] extends {
|
|
84
|
-
(...args: infer A0): any;
|
|
85
|
-
} ? (...args: OverloadArguments<A0>) => Result : never;
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Expectation functions simply check a _value_, but do not alter the type
|
|
89
|
-
* returned by each expectation.
|
|
90
|
-
*/
|
|
91
|
-
export interface ExpectationFunctions<T> extends OverloadFunctions<AsyncExpectations, Promise<Expectations<PromiseLike<T>>>>, OverloadFunctions<SyncExpectations, Expectations<T>> {
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* An interface describing all expectations returned by `expect(...)`.
|
|
95
|
-
*
|
|
96
|
-
* Each function, upon checking, might return an expectation bound to a
|
|
97
|
-
* different _type_ (for example `.toBeNull()` returns always
|
|
98
|
-
* `Expectations<null>`, inferring that `value` is indeed `null`).
|
|
99
|
-
*/
|
|
100
|
-
export interface Expectations<T = unknown> extends AllExpectations {
|
|
101
|
-
/** The value this {@link Expectations} instance operates on */
|
|
102
|
-
readonly value: T;
|
|
103
|
-
/** The _negated_ expectations of _this_ {@link Expectations} instance. */
|
|
104
|
-
readonly not: ExpectationFunctions<T>;
|
|
105
|
-
}
|
|
106
|
-
/** An interface describing all expectations returned by `expect(...)` */
|
|
107
|
-
export interface Matchers extends OverloadFunctions<SyncExpectations, Matchers> {
|
|
108
|
-
not: Matchers;
|
|
109
|
-
expect(value: unknown): void;
|
|
110
|
-
}
|
|
1
|
+
import { AsyncExpectations } from './async';
|
|
2
|
+
import { Matchers } from './matchers';
|
|
3
|
+
export type { AsyncExpectations } from './async';
|
|
4
|
+
export type { Expectations, NegativeExpectations } from './expectations';
|
|
5
|
+
export type { Matchers, NegativeMatchers } from './matchers';
|
|
111
6
|
/** The `expect` function exposing expectations and matchers */
|
|
112
|
-
export
|
|
113
|
-
|
|
7
|
+
export type Expect = {
|
|
8
|
+
<T = unknown>(value: T, remarks?: string): AsyncExpectations<T>;
|
|
9
|
+
} & Omit<Matchers, 'expect'>;
|
|
10
|
+
/** The `expect` function exposing expectations and matchers */
|
|
11
|
+
export declare const expect: Expect;
|
|
@@ -1,212 +1,17 @@
|
|
|
1
1
|
// expectation/expect.ts
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
toBeInstanceOf,
|
|
14
|
-
toBeLessThan,
|
|
15
|
-
toBeLessThanOrEqual,
|
|
16
|
-
toBeWithinRange,
|
|
17
|
-
toEqual,
|
|
18
|
-
toHaveLength,
|
|
19
|
-
toHaveProperty,
|
|
20
|
-
toHaveSize,
|
|
21
|
-
toMatch,
|
|
22
|
-
toStrictlyEqual
|
|
23
|
-
} from "./basic.mjs";
|
|
24
|
-
import {
|
|
25
|
-
toInclude,
|
|
26
|
-
toMatchContents
|
|
27
|
-
} from "./include.mjs";
|
|
28
|
-
import {
|
|
29
|
-
toThrow,
|
|
30
|
-
toThrowError
|
|
31
|
-
} from "./throwing.mjs";
|
|
32
|
-
import {
|
|
33
|
-
toBeDefined,
|
|
34
|
-
toBeFalse,
|
|
35
|
-
toBeFalsy,
|
|
36
|
-
toBeNaN,
|
|
37
|
-
toBeNegativeInfinity,
|
|
38
|
-
toBeNull,
|
|
39
|
-
toBeNullable,
|
|
40
|
-
toBePositiveInfinity,
|
|
41
|
-
toBeTrue,
|
|
42
|
-
toBeTruthy,
|
|
43
|
-
toBeUndefined
|
|
44
|
-
} from "./trivial.mjs";
|
|
45
|
-
import {
|
|
46
|
-
ExpectationError,
|
|
47
|
-
matcherMarker
|
|
48
|
-
} from "./types.mjs";
|
|
49
|
-
var asyncExpectations = {
|
|
50
|
-
toBeResolved,
|
|
51
|
-
toBeRejected,
|
|
52
|
-
toBeRejectedWithError
|
|
53
|
-
};
|
|
54
|
-
var syncExpectations = {
|
|
55
|
-
// basic
|
|
56
|
-
toBeA,
|
|
57
|
-
toBeCloseTo,
|
|
58
|
-
toBeError,
|
|
59
|
-
toBeGreaterThan,
|
|
60
|
-
toBeGreaterThanOrEqual,
|
|
61
|
-
toBeInstanceOf,
|
|
62
|
-
toBeLessThan,
|
|
63
|
-
toBeLessThanOrEqual,
|
|
64
|
-
toBeWithinRange,
|
|
65
|
-
toEqual,
|
|
66
|
-
toHaveLength,
|
|
67
|
-
toHaveProperty,
|
|
68
|
-
toHaveSize,
|
|
69
|
-
toMatch,
|
|
70
|
-
toStrictlyEqual,
|
|
71
|
-
// include
|
|
72
|
-
toInclude,
|
|
73
|
-
toMatchContents,
|
|
74
|
-
// throwing
|
|
75
|
-
toThrow,
|
|
76
|
-
toThrowError,
|
|
77
|
-
// trivial
|
|
78
|
-
toBeDefined,
|
|
79
|
-
toBeFalse,
|
|
80
|
-
toBeFalsy,
|
|
81
|
-
toBeNaN,
|
|
82
|
-
toBeNegativeInfinity,
|
|
83
|
-
toBeNull,
|
|
84
|
-
toBeNullable,
|
|
85
|
-
toBePositiveInfinity,
|
|
86
|
-
toBeTrue,
|
|
87
|
-
toBeTruthy,
|
|
88
|
-
toBeUndefined
|
|
89
|
-
};
|
|
90
|
-
var allExpectations = {
|
|
91
|
-
...asyncExpectations,
|
|
92
|
-
...syncExpectations
|
|
93
|
-
};
|
|
94
|
-
var ExpectationsContextImpl = class {
|
|
95
|
-
constructor(value, negative, expects, negated, parent) {
|
|
96
|
-
this.value = value;
|
|
97
|
-
this.negative = negative;
|
|
98
|
-
this.expects = expects;
|
|
99
|
-
this.negated = negated;
|
|
100
|
-
this.parent = parent;
|
|
101
|
-
}
|
|
102
|
-
forValue(value) {
|
|
103
|
-
return new ExpectationsImpl(value);
|
|
104
|
-
}
|
|
105
|
-
forProperty(prop) {
|
|
106
|
-
this.expects.toBeDefined();
|
|
107
|
-
const value = this.value[prop];
|
|
108
|
-
const parent = { context: this, prop };
|
|
109
|
-
return new ExpectationsImpl(value, parent);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
var ExpectationsImpl = class {
|
|
113
|
-
_context;
|
|
114
|
-
value;
|
|
115
|
-
not;
|
|
116
|
-
constructor(value, parent, positives) {
|
|
117
|
-
this.value = value;
|
|
118
|
-
if (positives) {
|
|
119
|
-
this.not = positives;
|
|
120
|
-
this._context = new ExpectationsContextImpl(
|
|
121
|
-
value,
|
|
122
|
-
true,
|
|
123
|
-
positives,
|
|
124
|
-
this,
|
|
125
|
-
parent
|
|
126
|
-
);
|
|
127
|
-
} else {
|
|
128
|
-
this._context = new ExpectationsContextImpl(
|
|
129
|
-
value,
|
|
130
|
-
false,
|
|
131
|
-
this,
|
|
132
|
-
this,
|
|
133
|
-
parent
|
|
134
|
-
);
|
|
135
|
-
this.not = new ExpectationsImpl(value, parent, this);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
static {
|
|
139
|
-
for (const [key, value] of Object.entries(allExpectations)) {
|
|
140
|
-
const expectation = value;
|
|
141
|
-
const fn = function(...args) {
|
|
142
|
-
try {
|
|
143
|
-
return expectation.call(this._context, ...args);
|
|
144
|
-
} catch (error) {
|
|
145
|
-
if (error instanceof ExpectationError)
|
|
146
|
-
Error.captureStackTrace(error, fn);
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
Object.defineProperty(fn, "name", { value: key });
|
|
151
|
-
Object.defineProperty(this.prototype, key, { value: fn });
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
var MatcherImpl = class {
|
|
156
|
-
_matchers;
|
|
157
|
-
_positiveBuilder;
|
|
158
|
-
_negativeBuilder;
|
|
159
|
-
_negative;
|
|
160
|
-
constructor(_matchers, _positiveBuilder) {
|
|
161
|
-
this._matchers = _matchers;
|
|
162
|
-
if (_positiveBuilder) {
|
|
163
|
-
this._negative = true;
|
|
164
|
-
this._positiveBuilder = _positiveBuilder;
|
|
165
|
-
this._negativeBuilder = this;
|
|
166
|
-
} else {
|
|
167
|
-
this._negative = false;
|
|
168
|
-
this._positiveBuilder = this;
|
|
169
|
-
this._negativeBuilder = new MatcherImpl(this._matchers, this);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
get not() {
|
|
173
|
-
return this._negative ? this._positiveBuilder : this._negativeBuilder;
|
|
174
|
-
}
|
|
175
|
-
expect(value) {
|
|
176
|
-
const expectations = expect(value);
|
|
177
|
-
for (const [expectation, negative, args] of this._matchers) {
|
|
178
|
-
const expect2 = negative ? expectations.not : expectations;
|
|
179
|
-
expect2[expectation](...args);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
static {
|
|
183
|
-
Object.defineProperty(this.prototype, matcherMarker, { value: matcherMarker });
|
|
184
|
-
for (const key in syncExpectations) {
|
|
185
|
-
Object.defineProperty(this.prototype, key, {
|
|
186
|
-
value: function(...args) {
|
|
187
|
-
return new MatcherImpl([
|
|
188
|
-
...this._matchers,
|
|
189
|
-
[key, this._negative, args]
|
|
190
|
-
]);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
var expect = (value) => {
|
|
197
|
-
return new ExpectationsImpl(value);
|
|
198
|
-
};
|
|
199
|
-
Object.defineProperty(expect, "not", {
|
|
200
|
-
get: () => new MatcherImpl([]).not
|
|
201
|
-
});
|
|
202
|
-
for (const name in syncExpectations) {
|
|
203
|
-
Object.defineProperty(expect, name, {
|
|
204
|
-
value: function(...args) {
|
|
205
|
-
const builder = new MatcherImpl([]);
|
|
206
|
-
return builder[name](...args);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
2
|
+
import { AsyncExpectations } from "./async.mjs";
|
|
3
|
+
import { Matchers } from "./matchers.mjs";
|
|
4
|
+
var expect = (value, remarks) => {
|
|
5
|
+
return new AsyncExpectations(value, remarks);
|
|
6
|
+
};
|
|
7
|
+
for (const key of Object.getOwnPropertyNames(Matchers.prototype)) {
|
|
8
|
+
if (!key.startsWith("to"))
|
|
9
|
+
continue;
|
|
10
|
+
const matcher = (...args) => new Matchers()[key](...args);
|
|
11
|
+
Object.defineProperty(matcher, "name", { value: key });
|
|
12
|
+
Object.defineProperty(expect, key, { value: matcher });
|
|
209
13
|
}
|
|
14
|
+
Object.defineProperty(expect, "not", { get: () => new Matchers().not });
|
|
210
15
|
export {
|
|
211
16
|
expect
|
|
212
17
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/expectation/expect.ts"],
|
|
4
|
-
"mappings": ";AAAA
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": ";AAAA,SAAS,yBAAyB;AAClC,SAAS,gBAAgB;AAgBlB,IAAM,SAAkB,CAAC,OAAY,YAAqB;AAC/D,SAAO,IAAI,kBAAkB,OAAO,OAAO;AAC7C;AAGA,WAAW,OAAO,OAAO,oBAAoB,SAAS,SAAS,GAAG;AAChE,MAAI,CAAE,IAAI,WAAW,IAAI;AAAG;AAE5B,QAAM,UAAU,IAAI,SAAuB,IAAI,SAAS,EAAU,GAAG,EAAE,GAAG,IAAI;AAC9E,SAAO,eAAe,SAAS,QAAQ,EAAE,OAAO,IAAI,CAAC;AACrD,SAAO,eAAe,QAAQ,KAAK,EAAE,OAAO,QAAQ,CAAC;AACvD;AAGA,OAAO,eAAe,QAAQ,OAAO,EAAE,KAAK,MAAM,IAAI,SAAS,EAAE,IAAI,CAAC;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|