@plugjs/expect5 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +1 -1
- package/dist/expectation/async.cjs +73 -0
- package/dist/expectation/async.cjs.map +6 -0
- package/dist/expectation/async.d.ts +54 -0
- package/dist/expectation/async.mjs +46 -0
- package/dist/expectation/async.mjs.map +6 -0
- package/dist/expectation/basic.cjs +155 -183
- package/dist/expectation/basic.cjs.map +1 -1
- package/dist/expectation/basic.d.ts +90 -47
- package/dist/expectation/basic.mjs +142 -163
- package/dist/expectation/basic.mjs.map +1 -1
- package/dist/expectation/diff.cjs +7 -7
- package/dist/expectation/diff.cjs.map +1 -1
- package/dist/expectation/diff.mjs +7 -7
- package/dist/expectation/diff.mjs.map +1 -1
- package/dist/expectation/expect.cjs +94 -108
- package/dist/expectation/expect.cjs.map +2 -2
- package/dist/expectation/expect.d.ts +103 -130
- package/dist/expectation/expect.mjs +131 -137
- package/dist/expectation/expect.mjs.map +2 -2
- package/dist/expectation/include.cjs +50 -61
- package/dist/expectation/include.cjs.map +1 -1
- package/dist/expectation/include.d.ts +19 -10
- package/dist/expectation/include.mjs +53 -57
- package/dist/expectation/include.mjs.map +1 -1
- package/dist/expectation/throwing.cjs +27 -27
- package/dist/expectation/throwing.cjs.map +1 -1
- package/dist/expectation/throwing.d.ts +36 -8
- package/dist/expectation/throwing.mjs +26 -26
- package/dist/expectation/throwing.mjs.map +1 -1
- package/dist/expectation/trivial.cjs +96 -0
- package/dist/expectation/trivial.cjs.map +6 -0
- package/dist/expectation/trivial.d.ts +13 -0
- package/dist/expectation/trivial.mjs +61 -0
- package/dist/expectation/trivial.mjs.map +6 -0
- package/dist/expectation/types.cjs +9 -12
- package/dist/expectation/types.cjs.map +1 -1
- package/dist/expectation/types.d.ts +52 -10
- package/dist/expectation/types.mjs +8 -10
- package/dist/expectation/types.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/expectation/async.ts +151 -0
- package/src/expectation/basic.ts +356 -156
- package/src/expectation/diff.ts +8 -9
- package/src/expectation/expect.ts +239 -268
- package/src/expectation/include.ts +93 -59
- package/src/expectation/throwing.ts +102 -41
- package/src/expectation/trivial.ts +107 -0
- package/src/expectation/types.ts +82 -25
- package/src/index.ts +2 -0
- package/dist/expectation/void.cjs +0 -111
- package/dist/expectation/void.cjs.map +0 -6
- package/dist/expectation/void.d.ts +0 -39
- package/dist/expectation/void.mjs +0 -77
- package/dist/expectation/void.mjs.map +0 -6
- package/src/expectation/void.ts +0 -80
|
@@ -23,122 +23,107 @@ __export(expect_exports, {
|
|
|
23
23
|
expect: () => expect
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(expect_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_async = require("./async.cjs");
|
|
27
27
|
var import_basic = require("./basic.cjs");
|
|
28
28
|
var import_include = require("./include.cjs");
|
|
29
29
|
var import_throwing = require("./throwing.cjs");
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
var import_trivial = require("./trivial.cjs");
|
|
31
|
+
var import_types = require("./types.cjs");
|
|
32
|
+
var asyncExpectations = {
|
|
33
|
+
toBeResolved: import_async.toBeResolved,
|
|
34
|
+
toBeRejected: import_async.toBeRejected,
|
|
35
|
+
toBeRejectedWithError: import_async.toBeRejectedWithError
|
|
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,
|
|
48
54
|
// include
|
|
49
|
-
toInclude:
|
|
50
|
-
toMatchContents:
|
|
55
|
+
toInclude: import_include.toInclude,
|
|
56
|
+
toMatchContents: import_include.toMatchContents,
|
|
51
57
|
// throwing
|
|
52
|
-
toThrow:
|
|
53
|
-
toThrowError:
|
|
54
|
-
//
|
|
55
|
-
toBeDefined:
|
|
56
|
-
toBeFalse:
|
|
57
|
-
toBeFalsy:
|
|
58
|
-
toBeNaN:
|
|
59
|
-
toBeNegativeInfinity:
|
|
60
|
-
toBeNull:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
65
72
|
};
|
|
66
|
-
var
|
|
67
|
-
|
|
73
|
+
var allExpectations = {
|
|
74
|
+
...asyncExpectations,
|
|
75
|
+
...syncExpectations
|
|
76
|
+
};
|
|
77
|
+
var ExpectationsContextImpl = class {
|
|
78
|
+
constructor(value, negative, expects, negated, parent) {
|
|
68
79
|
this.value = value;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} else {
|
|
74
|
-
this._negative = false;
|
|
75
|
-
this._positiveExpectations = this;
|
|
76
|
-
this._negativeExpectations = new ExpectationsImpl(value, this);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
_positiveExpectations;
|
|
80
|
-
_negativeExpectations;
|
|
81
|
-
_negative;
|
|
82
|
-
/* == NEW EXPECTATIONS ==================================================== */
|
|
83
|
-
forProperty(prop) {
|
|
84
|
-
this.toBeDefined();
|
|
85
|
-
const child = new ExpectationsImpl(this.value[prop]);
|
|
86
|
-
child.parent = { context: this, prop };
|
|
87
|
-
return child;
|
|
80
|
+
this.negative = negative;
|
|
81
|
+
this.expects = expects;
|
|
82
|
+
this.negated = negated;
|
|
83
|
+
this.parent = parent;
|
|
88
84
|
}
|
|
89
85
|
forValue(value) {
|
|
90
86
|
return new ExpectationsImpl(value);
|
|
91
87
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return this._negative ? this._positiveExpectations : this._negativeExpectations;
|
|
98
|
-
}
|
|
99
|
-
/* == ASYNCHRONOUS EXPECTATIONS =========================================== */
|
|
100
|
-
toBeResolved(assert) {
|
|
101
|
-
return Promise.resolve().then(() => {
|
|
102
|
-
this._positiveExpectations.toHaveProperty("then", (a) => a.toBeA("function"));
|
|
103
|
-
return Promise.allSettled([Promise.resolve(this.value)]);
|
|
104
|
-
}).then(([settlement]) => {
|
|
105
|
-
if (settlement.status === "fulfilled") {
|
|
106
|
-
if (this._negative)
|
|
107
|
-
throw new import_types.ExpectationError(this, true, "to be resolved");
|
|
108
|
-
if (assert)
|
|
109
|
-
assert(new ExpectationsImpl(settlement.value));
|
|
110
|
-
} else if (!this._negative) {
|
|
111
|
-
throw new import_types.ExpectationError(this, false, "to be resolved");
|
|
112
|
-
}
|
|
113
|
-
return this._positiveExpectations;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
toBeRejected(assert) {
|
|
117
|
-
return Promise.resolve().then(() => {
|
|
118
|
-
this._positiveExpectations.toHaveProperty("then", (a) => a.toBeA("function"));
|
|
119
|
-
return Promise.allSettled([Promise.resolve(this.value)]);
|
|
120
|
-
}).then(([settlement]) => {
|
|
121
|
-
if (settlement.status === "rejected") {
|
|
122
|
-
if (this._negative)
|
|
123
|
-
throw new import_types.ExpectationError(this, true, "to be rejected");
|
|
124
|
-
if (assert)
|
|
125
|
-
assert(new ExpectationsImpl(settlement.reason));
|
|
126
|
-
} else if (!this._negative) {
|
|
127
|
-
throw new import_types.ExpectationError(this, false, "to be rejected");
|
|
128
|
-
}
|
|
129
|
-
return this._positiveExpectations;
|
|
130
|
-
});
|
|
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);
|
|
131
93
|
}
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
}
|
|
134
120
|
}
|
|
135
121
|
static {
|
|
136
|
-
for (const [key, value] of Object.entries(
|
|
122
|
+
for (const [key, value] of Object.entries(allExpectations)) {
|
|
137
123
|
const expectation = value;
|
|
138
124
|
const fn = function(...args) {
|
|
139
125
|
try {
|
|
140
|
-
expectation.
|
|
141
|
-
return this._positiveExpectations;
|
|
126
|
+
return expectation.call(this._context, ...args);
|
|
142
127
|
} catch (error) {
|
|
143
128
|
if (error instanceof import_types.ExpectationError)
|
|
144
129
|
Error.captureStackTrace(error, fn);
|
|
@@ -150,7 +135,7 @@ var ExpectationsImpl = class {
|
|
|
150
135
|
}
|
|
151
136
|
}
|
|
152
137
|
};
|
|
153
|
-
var
|
|
138
|
+
var MatcherImpl = class {
|
|
154
139
|
_matchers;
|
|
155
140
|
_positiveBuilder;
|
|
156
141
|
_negativeBuilder;
|
|
@@ -164,24 +149,25 @@ var ExpectationsMatcherImpl = class {
|
|
|
164
149
|
} else {
|
|
165
150
|
this._negative = false;
|
|
166
151
|
this._positiveBuilder = this;
|
|
167
|
-
this._negativeBuilder = new
|
|
152
|
+
this._negativeBuilder = new MatcherImpl(this._matchers, this);
|
|
168
153
|
}
|
|
169
154
|
}
|
|
170
155
|
get not() {
|
|
171
156
|
return this._negative ? this._positiveBuilder : this._negativeBuilder;
|
|
172
157
|
}
|
|
173
158
|
expect(value) {
|
|
174
|
-
const
|
|
159
|
+
const expectations = expect(value);
|
|
175
160
|
for (const [expectation, negative, args] of this._matchers) {
|
|
176
|
-
|
|
161
|
+
const expect2 = negative ? expectations.not : expectations;
|
|
162
|
+
expect2[expectation](...args);
|
|
177
163
|
}
|
|
178
164
|
}
|
|
179
165
|
static {
|
|
180
166
|
Object.defineProperty(this.prototype, import_types.matcherMarker, { value: import_types.matcherMarker });
|
|
181
|
-
for (const key in
|
|
167
|
+
for (const key in syncExpectations) {
|
|
182
168
|
Object.defineProperty(this.prototype, key, {
|
|
183
169
|
value: function(...args) {
|
|
184
|
-
return new
|
|
170
|
+
return new MatcherImpl([
|
|
185
171
|
...this._matchers,
|
|
186
172
|
[key, this._negative, args]
|
|
187
173
|
]);
|
|
@@ -194,12 +180,12 @@ var expect = (value) => {
|
|
|
194
180
|
return new ExpectationsImpl(value);
|
|
195
181
|
};
|
|
196
182
|
Object.defineProperty(expect, "not", {
|
|
197
|
-
get: () => new
|
|
183
|
+
get: () => new MatcherImpl([]).not
|
|
198
184
|
});
|
|
199
|
-
for (const name in
|
|
185
|
+
for (const name in syncExpectations) {
|
|
200
186
|
Object.defineProperty(expect, name, {
|
|
201
187
|
value: function(...args) {
|
|
202
|
-
const builder = new
|
|
188
|
+
const builder = new MatcherImpl([]);
|
|
203
189
|
return builder[name](...args);
|
|
204
190
|
}
|
|
205
191
|
});
|
|
@@ -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,mBAIO;AACP,mBAgBO;AACP,qBAGO;AACP,sBAGO;AACP,qBAYO;AACP,mBAGO;AAWP,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AACF;AAIA,IAAM,mBAAmB;AAAA;AAAA,EAEvB;AAAA,EACA;A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;AAAA,YAAW,CAAE,KAAK,KAAK,WAAW,IAAK;AAAA,UACjD,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAOO,IAAM,SAAU,CAAc,UAA8B;AACjE,SAAO,IAAI,iBAAiB,KAAK;AACnC;AAGA,OAAO,eAAe,QAAQ,OAAO;AAAA,EACnC,KAAK,MAAM,IAAI,YAAY,CAAC,CAAC,EAAE;AACjC,CAAC;AAGD,WAAW,QAAQ,kBAAkB;AACnC,SAAO,eAAe,QAAQ,MAAM;AAAA,IAClC,OAAO,YAAY,MAAuB;AACxC,YAAM,UAAU,IAAI,YAAY,CAAC,CAAC;AAClC,aAAQ,QAAgB,IAAI,EAAE,GAAG,IAAI;AAAA,IACvC;AAAA,EACF,CAAC;AACH;",
|
|
5
|
+
"names": ["expect"]
|
|
6
6
|
}
|
|
@@ -1,140 +1,113 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly toBeError: ToBeError;
|
|
11
|
-
readonly toBeGreaterThan: ToBeGreaterThan;
|
|
12
|
-
readonly toBeGreaterThanOrEqual: ToBeGreaterThanOrEqual;
|
|
13
|
-
readonly toBeInstanceOf: ToBeInstanceOf;
|
|
14
|
-
readonly toBeLessThan: ToBeLessThan;
|
|
15
|
-
readonly toBeLessThanOrEqual: ToBeLessThanOrEqual;
|
|
16
|
-
readonly toBeWithinRange: ToBeWithinRange;
|
|
17
|
-
readonly toEqual: ToEqual;
|
|
18
|
-
readonly toHaveLength: ToHaveLength;
|
|
19
|
-
readonly toHaveProperty: ToHaveProperty;
|
|
20
|
-
readonly toHaveSize: ToHaveSize;
|
|
21
|
-
readonly toMatch: ToMatch;
|
|
22
|
-
readonly toStrictlyEqual: ToStrictlyEqual;
|
|
23
|
-
readonly toInclude: ToInclude;
|
|
24
|
-
readonly toMatchContents: ToMatchContents;
|
|
25
|
-
readonly toThrow: ToThrow;
|
|
26
|
-
readonly toThrowError: ToThrowError;
|
|
27
|
-
readonly toBeDefined: ToBeDefined;
|
|
28
|
-
readonly toBeFalse: ToBeFalse;
|
|
29
|
-
readonly toBeFalsy: ToBeFalsy;
|
|
30
|
-
readonly toBeNaN: ToBeNaN;
|
|
31
|
-
readonly toBeNegativeInfinity: ToBeNegativeInfinity;
|
|
32
|
-
readonly toBeNull: ToBeNull;
|
|
33
|
-
readonly toBePositiveInfinity: ToBePositiveInfinity;
|
|
34
|
-
readonly toBeTrue: ToBeTrue;
|
|
35
|
-
readonly toBeTruthy: ToBeTruthy;
|
|
36
|
-
readonly toBeUndefined: ToBeUndefined;
|
|
1
|
+
import { toBeRejected, toBeRejectedWithError, toBeResolved } from './async';
|
|
2
|
+
import { toBeA, toBeCloseTo, toBeError, toBeGreaterThan, toBeGreaterThanOrEqual, toBeInstanceOf, toBeLessThan, toBeLessThanOrEqual, toBeWithinRange, toEqual, toHaveLength, toHaveProperty, toHaveSize, toMatch, toStrictlyEqual } from './basic';
|
|
3
|
+
import { toInclude, toMatchContents } from './include';
|
|
4
|
+
import { toThrow, toThrowError } from './throwing';
|
|
5
|
+
import { toBeDefined, toBeFalse, toBeFalsy, toBeNaN, toBeNegativeInfinity, toBeNull, toBeNullable, toBePositiveInfinity, toBeTrue, toBeTruthy, toBeUndefined } from './trivial';
|
|
6
|
+
declare const asyncExpectations: {
|
|
7
|
+
readonly toBeResolved: typeof toBeResolved;
|
|
8
|
+
readonly toBeRejected: typeof toBeRejected;
|
|
9
|
+
readonly toBeRejectedWithError: typeof toBeRejectedWithError;
|
|
37
10
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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;
|
|
47
43
|
};
|
|
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
|
-
* of the specified _type_ and with the specified _message_
|
|
97
|
-
*/
|
|
98
|
-
toBeRejectedWithError(constructor: Constructor<Error>, message: StringMatcher): Promise<Expectations<T>>;
|
|
99
|
-
}
|
|
100
|
-
/** Parent expectations */
|
|
101
|
-
export interface ExpectationsParent {
|
|
102
|
-
context: Expectations;
|
|
103
|
-
prop: string | number | symbol;
|
|
104
|
-
}
|
|
105
|
-
/** Basic definition of an {@link Expectation} as an object */
|
|
106
|
-
export interface Expectation {
|
|
107
|
-
expect(context: Expectations, negative: boolean, ...args: any[]): void;
|
|
108
|
-
}
|
|
109
|
-
/** Empty interface: the `class` below won't complain about missing stuff */
|
|
110
|
-
interface ExpectationsImpl<T = unknown> extends Expectations<T> {
|
|
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>> {
|
|
111
92
|
}
|
|
112
|
-
/**
|
|
113
|
-
|
|
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 */
|
|
114
102
|
readonly value: T;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
private readonly _negative;
|
|
118
|
-
constructor(value: T, _positiveExpectations?: ExpectationsImpl<T>);
|
|
119
|
-
forProperty(prop: string | number | symbol): ExpectationsImpl;
|
|
120
|
-
forValue<T = unknown>(value: T): ExpectationsImpl<T>;
|
|
121
|
-
negated(negative: boolean): ExpectationsImpl<T>;
|
|
122
|
-
get not(): ExpectationsImpl<T>;
|
|
123
|
-
toBeResolved(assert?: (resultExpectations: Expectations) => void): Promise<ExpectationsImpl<T>>;
|
|
124
|
-
toBeRejected(assert?: (reasonExpectations: Expectations) => void): Promise<ExpectationsImpl<T>>;
|
|
125
|
-
toBeRejectedWithError(...args: [] | [message: StringMatcher] | [constructor: Constructor<Error>] | [constructor: Constructor<Error>, message: StringMatcher]): Promise<ExpectationsImpl<T>>;
|
|
103
|
+
/** The _negated_ expectations of _this_ {@link Expectations} instance. */
|
|
104
|
+
readonly not: ExpectationFunctions<T>;
|
|
126
105
|
}
|
|
127
|
-
/** Infer return parameter from {@link Expectation} type */
|
|
128
|
-
type MatcherReturn<E> = E extends Expectation ? ExpectationsMatcher : never;
|
|
129
|
-
/** Infer expectation functions from imported {@link Expectation} instances */
|
|
130
|
-
type ImportedMatchers = {
|
|
131
|
-
[k in keyof ExpectationsByName]: (...args: ExpectationParameters<ExpectationsByName[k]>) => MatcherReturn<ExpectationsByName[k]>;
|
|
132
|
-
};
|
|
133
106
|
/** An interface describing all expectations returned by `expect(...)` */
|
|
134
|
-
export interface
|
|
135
|
-
not:
|
|
107
|
+
export interface Matchers extends OverloadFunctions<SyncExpectations, Matchers> {
|
|
108
|
+
not: Matchers;
|
|
136
109
|
expect(value: unknown): void;
|
|
137
110
|
}
|
|
138
111
|
/** The `expect` function exposing expectations and matchers */
|
|
139
|
-
export declare const expect:
|
|
112
|
+
export declare const expect: Matchers & (<T = unknown>(value: T) => Expectations<T>);
|
|
140
113
|
export {};
|