@plugjs/expect5 0.4.4 → 0.4.6
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 +78 -45
- package/dist/expectation/async.cjs.map +1 -1
- package/dist/expectation/async.d.ts +66 -51
- package/dist/expectation/async.mjs +79 -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 +33 -5
- package/dist/test.cjs.map +1 -1
- package/dist/test.d.ts +2 -2
- package/dist/test.mjs +34 -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 +145 -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 +33 -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
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { Expectations, type AssertedType, type AssertionFunction, type InferMatchers } from './expectations';
|
|
2
|
+
import { type Constructor, type TypeMappings, type TypeName } from './types';
|
|
3
|
+
type Matcher = (expectations: Expectations) => Expectations;
|
|
4
|
+
export declare class Matchers<T = unknown> {
|
|
5
|
+
private readonly _matchers;
|
|
6
|
+
readonly not: NegativeMatchers<T>;
|
|
7
|
+
constructor();
|
|
8
|
+
expect(value: unknown): T;
|
|
9
|
+
private _push;
|
|
10
|
+
/**
|
|
11
|
+
* Expects the value to be of the specified _extended_ {@link TypeName type},
|
|
12
|
+
* and (if specified) further asserts it with an {@link AssertionFunction}.
|
|
13
|
+
*
|
|
14
|
+
* Negation: {@link NegativeMatchers.toBeA `not.toBeA(...)`}
|
|
15
|
+
*/
|
|
16
|
+
toBeA<Name extends TypeName, Mapped extends TypeMappings[Name], Assert extends AssertionFunction<Mapped>>(type: Name, assertion?: Assert): Matchers<AssertedType<Mapped, Assert>>;
|
|
17
|
+
/**
|
|
18
|
+
* Expects the value to be a `number` within a given +/- _delta_ range of the
|
|
19
|
+
* specified expected value.
|
|
20
|
+
*
|
|
21
|
+
* Negation: {@link NegativeMatchers.toBeCloseTo `not.toBeCloseTo(...)`}
|
|
22
|
+
*/
|
|
23
|
+
toBeCloseTo(value: number, delta: number): Matchers<number>;
|
|
24
|
+
/**
|
|
25
|
+
* Expects the value to be a `bigint` within a given +/- _delta_ range of the
|
|
26
|
+
* specified expected value.
|
|
27
|
+
*
|
|
28
|
+
* Negation: {@link NegativeMatchers.toBeCloseTo `not.toBeCloseTo(...)`}
|
|
29
|
+
*/
|
|
30
|
+
toBeCloseTo(value: bigint, delta: bigint): Matchers<bigint>;
|
|
31
|
+
/**
|
|
32
|
+
* Expects the value to be neither `null` nor `undefined`.
|
|
33
|
+
*
|
|
34
|
+
* Negation: {@link NegativeMatchers.toBeDefined `not.toBeDefined()`}
|
|
35
|
+
*/
|
|
36
|
+
toBeDefined(): Matchers<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Expect the value to be an instance of {@link Error}.
|
|
39
|
+
*
|
|
40
|
+
* If specified, the {@link Error}'s own message will be further expected to
|
|
41
|
+
* either match the specified {@link RegExp}, or equal the specified `string`.
|
|
42
|
+
*/
|
|
43
|
+
toBeError(message?: string | RegExp): Matchers<Error>;
|
|
44
|
+
/**
|
|
45
|
+
* Expect the value to be an instance of {@link Error} and further asserts
|
|
46
|
+
* it to be an instance of the specifed {@link Error} {@link Constructor}.
|
|
47
|
+
*
|
|
48
|
+
* If specified, the {@link Error}'s own message will be further expected to
|
|
49
|
+
* either match the specified {@link RegExp}, or equal the specified `string`.
|
|
50
|
+
*/
|
|
51
|
+
toBeError<Class extends Constructor<Error>>(constructor: Class, message?: string | RegExp): Matchers<InstanceType<Class>>;
|
|
52
|
+
/** Expects the value strictly equal to `false`. */
|
|
53
|
+
toBeFalse(): Matchers<false>;
|
|
54
|
+
/**
|
|
55
|
+
* Expects the value to be _falsy_ (zero, empty string, `false`, ...).
|
|
56
|
+
*
|
|
57
|
+
* Negation: {@link Matchers.toBeTruthy `toBeTruthy()`}
|
|
58
|
+
*/
|
|
59
|
+
toBeFalsy(): Matchers<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Expects the value to be a `number` greater than the specified* expected
|
|
62
|
+
* value.
|
|
63
|
+
*
|
|
64
|
+
* Negation: {@link Matchers.toBeLessThanOrEqual `toBeLessThanOrEqual(...)`}
|
|
65
|
+
*/
|
|
66
|
+
toBeGreaterThan(value: number): Matchers<number>;
|
|
67
|
+
/**
|
|
68
|
+
* Expects the value to be a `bigint` greater than the specified expected
|
|
69
|
+
* value.
|
|
70
|
+
*
|
|
71
|
+
* Negation: {@link Matchers.toBeLessThanOrEqual `toBeLessThanOrEqual(...)`}
|
|
72
|
+
*/
|
|
73
|
+
toBeGreaterThan(value: bigint): Matchers<bigint>;
|
|
74
|
+
/**
|
|
75
|
+
* Expects the value to be a `number` greater than or equal to the specified
|
|
76
|
+
* expected value.
|
|
77
|
+
*
|
|
78
|
+
* Negation: {@link Matchers.toBeLessThan `toBeLessThan(...)`}
|
|
79
|
+
*/
|
|
80
|
+
toBeGreaterThanOrEqual(value: number): Matchers<number>;
|
|
81
|
+
/**
|
|
82
|
+
* Expects the value to be a `bigint` greater than or equal to the specified
|
|
83
|
+
* expected value.
|
|
84
|
+
*
|
|
85
|
+
* Negation: {@link Matchers.toBeLessThan `toBeLessThan(...)`}
|
|
86
|
+
*/
|
|
87
|
+
toBeGreaterThanOrEqual(value: bigint): Matchers<bigint>;
|
|
88
|
+
/**
|
|
89
|
+
* Expects the value to be an instance of the specified {@link Constructor},
|
|
90
|
+
* and (if specified) further asserts it with an {@link AssertionFunction}.
|
|
91
|
+
*
|
|
92
|
+
* Negation: {@link NegativeMatchers.toBeInstanceOf `not.toInstanceOf(...)`}
|
|
93
|
+
*/
|
|
94
|
+
toBeInstanceOf<Class extends Constructor, Assert extends AssertionFunction<InstanceType<Class>>>(constructor: Class, assertion?: Assert): Matchers<AssertedType<InstanceType<Class>, Assert>>;
|
|
95
|
+
/**
|
|
96
|
+
* Expects the value to be a `number` less than the specified expected value.
|
|
97
|
+
*
|
|
98
|
+
* Negation: {@link Matchers.toBeGreaterThanOrEqual `toBeGreaterThanOrEqual(...)`}
|
|
99
|
+
*/
|
|
100
|
+
toBeLessThan(value: number): Matchers<number>;
|
|
101
|
+
/**
|
|
102
|
+
* Expects the value to be a `bigint` less than the specified expected value.
|
|
103
|
+
*
|
|
104
|
+
* Negation: {@link Matchers.toBeGreaterThanOrEqual `toBeGreaterThanOrEqual(...)`}
|
|
105
|
+
*/
|
|
106
|
+
toBeLessThan(value: bigint): Matchers<bigint>;
|
|
107
|
+
/**
|
|
108
|
+
* Expects the value to be a `number` less than or equal to* the specified
|
|
109
|
+
* expected value.
|
|
110
|
+
*
|
|
111
|
+
* Negation: {@link Matchers.toBeGreaterThan `toBeGreaterThan(...)`}
|
|
112
|
+
*/
|
|
113
|
+
toBeLessThanOrEqual(value: number): Matchers<number>;
|
|
114
|
+
/**
|
|
115
|
+
* Expects the value to be a `bigint` less than or equal to the specified
|
|
116
|
+
* expected value.
|
|
117
|
+
*
|
|
118
|
+
* Negation: {@link Matchers.toBeGreaterThan `toBeGreaterThan(...)`}
|
|
119
|
+
*/
|
|
120
|
+
toBeLessThanOrEqual(value: bigint): Matchers<bigint>;
|
|
121
|
+
/**
|
|
122
|
+
* Expects the value to be `NaN`.
|
|
123
|
+
*
|
|
124
|
+
* Negation: {@link NegativeMatchers.toBeNaN `not.toBeNaN()`}
|
|
125
|
+
*/
|
|
126
|
+
toBeNaN(): Matchers<number>;
|
|
127
|
+
/** Expects the value to strictly equal `null`. */
|
|
128
|
+
toBeNull(): Matchers<null>;
|
|
129
|
+
/** Expects the value to strictly equal `true`. */
|
|
130
|
+
toBeTrue(): Matchers<true>;
|
|
131
|
+
/**
|
|
132
|
+
* Expects the value to be _falsy_ (non-zero, non-empty string, ...).
|
|
133
|
+
*
|
|
134
|
+
* Negation: {@link Matchers.toBeFalsy `toBeFalsy()`}
|
|
135
|
+
*/
|
|
136
|
+
toBeTruthy(): Matchers<T>;
|
|
137
|
+
/** Expects the value to strictly equal `undefined`. */
|
|
138
|
+
toBeUndefined(): Matchers<undefined>;
|
|
139
|
+
/**
|
|
140
|
+
* Expects the value to be a `number` within the specified range where the
|
|
141
|
+
* minimum and maximum values are inclusive.
|
|
142
|
+
*
|
|
143
|
+
* Negation: {@link NegativeMatchers.toBeWithinRange `not.toBeWithinRange(...)`}
|
|
144
|
+
*/
|
|
145
|
+
toBeWithinRange(min: number, max: number): Matchers<number>;
|
|
146
|
+
/**
|
|
147
|
+
* Expects the value to be a `bigint` within the specified range where the
|
|
148
|
+
* minimum and maximum values are inclusive.
|
|
149
|
+
*
|
|
150
|
+
* Negation: {@link NegativeMatchers.toBeWithinRange `not.toBeWithinRange(...)`}
|
|
151
|
+
*/
|
|
152
|
+
toBeWithinRange(min: bigint, max: bigint): Matchers<bigint>;
|
|
153
|
+
/**
|
|
154
|
+
* Expects the value to be _deep equal to_ the specified expected one.
|
|
155
|
+
*
|
|
156
|
+
* Negation: {@link NegativeMatchers.toEqual `not.toEqual(...)`}
|
|
157
|
+
*/
|
|
158
|
+
toEqual<Type>(expected: Type): Matchers<InferMatchers<Type>>;
|
|
159
|
+
/**
|
|
160
|
+
* Expects the value to have a `number` _property_ `length` with the specified
|
|
161
|
+
* expected value.
|
|
162
|
+
*
|
|
163
|
+
* Negation: {@link NegativeMatchers.toHaveLength `not.toHaveLength(...)`}
|
|
164
|
+
*/
|
|
165
|
+
toHaveLength(length: number): Matchers<T & {
|
|
166
|
+
length: number;
|
|
167
|
+
}>;
|
|
168
|
+
/**
|
|
169
|
+
* Expects the value to have the specified _property_ and (if specified)
|
|
170
|
+
* further asserts its value with an {@link AssertionFunction}.
|
|
171
|
+
*
|
|
172
|
+
* Negation: {@link NegativeMatchers.toHaveProperty `not.toHaveProperty(...)`}
|
|
173
|
+
*/
|
|
174
|
+
toHaveProperty<Prop extends string | number | symbol, Assert extends AssertionFunction>(property: Prop, assertion?: Assert): Matchers<T & {
|
|
175
|
+
[keyt in Prop]: AssertedType<unknown, Assert>;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Expects the value to have a `number` _property_ `size` with the specified
|
|
179
|
+
* expected value.
|
|
180
|
+
*
|
|
181
|
+
* Negation: {@link NegativeMatchers.toHaveSize `not.toHaveSize(...)`}
|
|
182
|
+
*/
|
|
183
|
+
toHaveSize(size: number): Matchers<T & {
|
|
184
|
+
size: number;
|
|
185
|
+
}>;
|
|
186
|
+
/**
|
|
187
|
+
* Expect the value to include _all_ properties from the specified _object_.
|
|
188
|
+
*
|
|
189
|
+
* If the object being expected is a {@link Map}, the properties specified
|
|
190
|
+
* here will be treated as _mappings_ for said {@link Map}.
|
|
191
|
+
*
|
|
192
|
+
* Negation: {@link NegativeMatchers.toInclude `not.toInclude(...)`}
|
|
193
|
+
*/
|
|
194
|
+
toInclude<P extends Record<string, any>>(properties: P): Matchers<T>;
|
|
195
|
+
/**
|
|
196
|
+
* Expect the value to include _all_ mappings from the specified {@link Map}.
|
|
197
|
+
*
|
|
198
|
+
* Negation: {@link NegativeMatchers.toInclude `not.toInclude(...)`}
|
|
199
|
+
*/
|
|
200
|
+
toInclude(mappings: Map<any, any>): Matchers<T>;
|
|
201
|
+
/**
|
|
202
|
+
* Expect the value to be an {@link Iterable} object includind _all_ values
|
|
203
|
+
* from the specified {@link Set}, in any order.
|
|
204
|
+
*
|
|
205
|
+
* Negation: {@link NegativeMatchers.toInclude `not.toInclude(...)`}
|
|
206
|
+
*/
|
|
207
|
+
toInclude(entries: Set<any>): Matchers<T>;
|
|
208
|
+
/**
|
|
209
|
+
* Expect the value to be an {@link Iterable} object includind _all_ values
|
|
210
|
+
* from the specified _array_, in any order.
|
|
211
|
+
*
|
|
212
|
+
* Negation: {@link NegativeMatchers.toInclude `not.toInclude(...)`}
|
|
213
|
+
*/
|
|
214
|
+
toInclude(values: any[]): Matchers<T>;
|
|
215
|
+
/**
|
|
216
|
+
* Expects the value to be a `string` _matching_ the specified sub-`string`
|
|
217
|
+
* or {@link RegExp}.
|
|
218
|
+
*
|
|
219
|
+
* Negation: {@link NegativeMatchers.toMatch `not.toMatch(...)`}
|
|
220
|
+
*/
|
|
221
|
+
toMatch<Matcher extends string | RegExp>(matcher: Matcher): Matchers<string>;
|
|
222
|
+
/**
|
|
223
|
+
* Expect the value to be an {@link Iterable} object includind _all_ values
|
|
224
|
+
* (and only those values) from the specified _array_, in any order.
|
|
225
|
+
*/
|
|
226
|
+
toMatchContents(contents: any[]): Matchers<T>;
|
|
227
|
+
/**
|
|
228
|
+
* Expect the value to be an {@link Iterable} object includind _all_ values
|
|
229
|
+
* (and only those values) from the specified {@link Set}, in any order.
|
|
230
|
+
*/
|
|
231
|
+
toMatchContents(contents: Set<any>): Matchers<T>;
|
|
232
|
+
/**
|
|
233
|
+
* Expects the value to be _strictly equal to_ the specified expected one.
|
|
234
|
+
*
|
|
235
|
+
* Negation: {@link NegativeMatchers.toStrictlyEqual `not.toStrictlyEqual(...)`}
|
|
236
|
+
*/
|
|
237
|
+
toStrictlyEqual<Type>(expected: Type): Matchers<Type>;
|
|
238
|
+
}
|
|
239
|
+
export declare class NegativeMatchers<T = unknown> {
|
|
240
|
+
private readonly _instance;
|
|
241
|
+
private readonly _matchers;
|
|
242
|
+
constructor(_instance: Matchers<T>, _matchers: Matcher[]);
|
|
243
|
+
private _push;
|
|
244
|
+
/**
|
|
245
|
+
* Expects the value _**NOT**_ to be of the specified _extended_
|
|
246
|
+
* {@link TypeName type}.
|
|
247
|
+
*
|
|
248
|
+
* Negates: {@link Matchers.toBeA `toBeA(...)`}
|
|
249
|
+
*/
|
|
250
|
+
toBeA(type: TypeName): Matchers<T>;
|
|
251
|
+
/**
|
|
252
|
+
* Expects the value to be a `number` _**OUTSIDE**_ of the given +/- _delta_
|
|
253
|
+
* range of the specified expected value.
|
|
254
|
+
*
|
|
255
|
+
* Negates: {@link Matchers.toBeCloseTo `toBeCloseTo(...)`}
|
|
256
|
+
*/
|
|
257
|
+
toBeCloseTo(value: number, delta: number): Matchers<number>;
|
|
258
|
+
/**
|
|
259
|
+
* Expects the value to be a `bigint` _**OUTSIDE**_ of the given +/- _delta_
|
|
260
|
+
* range of the specified expected value.
|
|
261
|
+
*
|
|
262
|
+
* Negates: {@link Matchers.toBeCloseTo `toBeCloseTo(...)`}
|
|
263
|
+
*/
|
|
264
|
+
toBeCloseTo(value: bigint, delta: bigint): Matchers<bigint>;
|
|
265
|
+
/**
|
|
266
|
+
* Expects the value to be either `null` or `undefined`.
|
|
267
|
+
*
|
|
268
|
+
* Negates: {@link Matchers.toBeDefined `toBeDefined()`}
|
|
269
|
+
*/
|
|
270
|
+
toBeDefined(): Matchers<null | undefined>;
|
|
271
|
+
/**
|
|
272
|
+
* Expects the value _**NOT**_ to be an instance of the specified
|
|
273
|
+
* {@link Constructor}.
|
|
274
|
+
*
|
|
275
|
+
* Negates: {@link Matchers.toBeInstanceOf `toBeInstanceOf(...)`}
|
|
276
|
+
*/
|
|
277
|
+
toBeInstanceOf(constructor: Constructor): Matchers<T>;
|
|
278
|
+
/**
|
|
279
|
+
* Expects the value _**NOT**_ to be `NaN`.
|
|
280
|
+
*
|
|
281
|
+
* Negates: {@link Matchers.toBeNaN `toBeNaN()`}
|
|
282
|
+
*/
|
|
283
|
+
toBeNaN(): Matchers<number>;
|
|
284
|
+
/**
|
|
285
|
+
* Expects the value to be a `number` _**OUTSIDE**_ of the specified range
|
|
286
|
+
* where minimum and maximum values are inclusive.
|
|
287
|
+
*
|
|
288
|
+
* Negates: {@link Matchers.toBeWithinRange `toBeWithinRange(...)`}
|
|
289
|
+
*/
|
|
290
|
+
toBeWithinRange(min: number, max: number): Matchers<number>;
|
|
291
|
+
/**
|
|
292
|
+
* Expects the value to be a `bigint` _**OUTSIDE**_ of the specified range
|
|
293
|
+
* where minimum and maximum values are inclusive.
|
|
294
|
+
*
|
|
295
|
+
* Negates: {@link Matchers.toBeWithinRange `toBeWithinRange(...)`}
|
|
296
|
+
*/
|
|
297
|
+
toBeWithinRange(min: bigint, max: bigint): Matchers<bigint>;
|
|
298
|
+
/**
|
|
299
|
+
* Expects the value _**NOT**_ to be _deep equal to_ the specified expected
|
|
300
|
+
* one.
|
|
301
|
+
*
|
|
302
|
+
* Negates: {@link Matchers.toEqual `toEqual(...)`}
|
|
303
|
+
*/
|
|
304
|
+
toEqual(expected: any): Matchers<T>;
|
|
305
|
+
/**
|
|
306
|
+
* Expects the value to have a `number` _property_ `length` _different_ from
|
|
307
|
+
* the specified expected value.
|
|
308
|
+
*
|
|
309
|
+
* Negates: {@link Matchers.toHaveLength `toHaveLength(...)`}
|
|
310
|
+
*/
|
|
311
|
+
toHaveLength(length: number): Matchers<T & {
|
|
312
|
+
length: number;
|
|
313
|
+
}>;
|
|
314
|
+
/**
|
|
315
|
+
* Expects the value _**NOT**_ to have the specified _property_.
|
|
316
|
+
*
|
|
317
|
+
* Negates: {@link Matchers.toHaveProperty `toHaveProperty(...)`}
|
|
318
|
+
*/
|
|
319
|
+
toHaveProperty(property: string | number | symbol): Matchers<T>;
|
|
320
|
+
/**
|
|
321
|
+
* Expects the value to have a `number` _property_ `size` _different_ from
|
|
322
|
+
* the specified expected value.
|
|
323
|
+
*
|
|
324
|
+
* Negates: {@link Matchers.toHaveSize `toHaveSize(...)`}
|
|
325
|
+
*/
|
|
326
|
+
toHaveSize(size: number): Matchers<T & {
|
|
327
|
+
size: number;
|
|
328
|
+
}>;
|
|
329
|
+
/**
|
|
330
|
+
* Expect the value to include _none_ of the properties from the specified
|
|
331
|
+
* _object_.
|
|
332
|
+
*
|
|
333
|
+
* If the object being expected is a {@link Map}, the properties specified
|
|
334
|
+
* here will be treated as _mappings_ for said {@link Map}.
|
|
335
|
+
*
|
|
336
|
+
* Negates: {@link Matchers.toInclude `toInclude(...)`}
|
|
337
|
+
*/
|
|
338
|
+
toInclude<P extends Record<string, any>>(properties: P): Matchers<T>;
|
|
339
|
+
/**
|
|
340
|
+
* Expect the value to include _none_ of the mappings from the specified
|
|
341
|
+
* {@link Map}.
|
|
342
|
+
*
|
|
343
|
+
* Negates: {@link Matchers.toInclude `toInclude(...)`}
|
|
344
|
+
*/
|
|
345
|
+
toInclude(mappings: Map<any, any>): Matchers<T>;
|
|
346
|
+
/**
|
|
347
|
+
* Expect the value to be an {@link Iterable} object includind _none_ of the
|
|
348
|
+
* values from the specified {@link Set}.
|
|
349
|
+
*
|
|
350
|
+
* Negates: {@link Matchers.toInclude `toInclude(...)`}
|
|
351
|
+
*/
|
|
352
|
+
toInclude(entries: Set<any>): Matchers<T>;
|
|
353
|
+
/**
|
|
354
|
+
* Expect the value to be an {@link Iterable} object includind _none_ of the
|
|
355
|
+
* values from the specified _array_.
|
|
356
|
+
*
|
|
357
|
+
* Negates: {@link Matchers.toInclude `toInclude(...)`}
|
|
358
|
+
*/
|
|
359
|
+
toInclude(values: any[]): Matchers<T>;
|
|
360
|
+
/**
|
|
361
|
+
* Expects the value to be a `string` _**NOT MATCHING**_ the specified
|
|
362
|
+
* sub-`string` or {@link RegExp}.
|
|
363
|
+
*
|
|
364
|
+
* Negates: {@link Matchers.toMatch `toMatch(...)`}
|
|
365
|
+
*/
|
|
366
|
+
toMatch(matcher: string | RegExp): Matchers<string>;
|
|
367
|
+
/**
|
|
368
|
+
* Expects the value _**NOT**_ to be _strictly equal to_ the specified
|
|
369
|
+
* expected one.
|
|
370
|
+
*
|
|
371
|
+
* Negates: {@link Matchers.toStrictlyEqual `toStrictlyEqual(...)`}
|
|
372
|
+
*/
|
|
373
|
+
toStrictlyEqual(expected: any): Matchers<T>;
|
|
374
|
+
}
|
|
375
|
+
export {};
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
// expectation/matchers.ts
|
|
2
|
+
import {
|
|
3
|
+
Expectations
|
|
4
|
+
} from "./expectations.mjs";
|
|
5
|
+
import {
|
|
6
|
+
matcherMarker
|
|
7
|
+
} from "./types.mjs";
|
|
8
|
+
var Matchers = class {
|
|
9
|
+
_matchers;
|
|
10
|
+
not;
|
|
11
|
+
constructor() {
|
|
12
|
+
const matchers = [];
|
|
13
|
+
this.not = new NegativeMatchers(this, matchers);
|
|
14
|
+
this._matchers = matchers;
|
|
15
|
+
}
|
|
16
|
+
expect(value) {
|
|
17
|
+
let expectations = new Expectations(value, void 0);
|
|
18
|
+
for (const matcher of this._matchers) {
|
|
19
|
+
expectations = matcher(expectations);
|
|
20
|
+
}
|
|
21
|
+
return expectations.value;
|
|
22
|
+
}
|
|
23
|
+
_push(matcher) {
|
|
24
|
+
const matchers = new Matchers();
|
|
25
|
+
matchers._matchers.push(...this._matchers, matcher);
|
|
26
|
+
return matchers;
|
|
27
|
+
}
|
|
28
|
+
static {
|
|
29
|
+
this.prototype[matcherMarker] = matcherMarker;
|
|
30
|
+
}
|
|
31
|
+
/* ------------------------------------------------------------------------ *
|
|
32
|
+
* BASIC *
|
|
33
|
+
* ------------------------------------------------------------------------ */
|
|
34
|
+
/**
|
|
35
|
+
* Expects the value to be of the specified _extended_ {@link TypeName type},
|
|
36
|
+
* and (if specified) further asserts it with an {@link AssertionFunction}.
|
|
37
|
+
*
|
|
38
|
+
* Negation: {@link NegativeMatchers.toBeA `not.toBeA(...)`}
|
|
39
|
+
*/
|
|
40
|
+
toBeA(type, assertion) {
|
|
41
|
+
return this._push((e) => e.toBeA(type, assertion));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Expects the value to be a `number` or `bigint` within a given +/- _delta_
|
|
45
|
+
* range of the specified expected value.
|
|
46
|
+
*
|
|
47
|
+
* Negation: {@link NegativeMatchers.toBeCloseTo `not.toBeCloseTo(...)`}
|
|
48
|
+
*/
|
|
49
|
+
toBeCloseTo(value, delta) {
|
|
50
|
+
return this._push((e) => e.toBeCloseTo(value, delta));
|
|
51
|
+
}
|
|
52
|
+
/* ------------------------------------------------------------------------ */
|
|
53
|
+
/**
|
|
54
|
+
* Expects the value to be neither `null` nor `undefined`.
|
|
55
|
+
*
|
|
56
|
+
* Negation: {@link NegativeMatchers.toBeDefined `not.toBeDefined()`}
|
|
57
|
+
*/
|
|
58
|
+
toBeDefined() {
|
|
59
|
+
return this._push((e) => e.toBeDefined());
|
|
60
|
+
}
|
|
61
|
+
toBeError(constructorOrMessage, maybeMessage) {
|
|
62
|
+
const [constructor, message] = typeof constructorOrMessage === "function" ? [constructorOrMessage, maybeMessage] : [Error, constructorOrMessage];
|
|
63
|
+
return this._push((e) => e.toBeError(constructor, message));
|
|
64
|
+
}
|
|
65
|
+
/* ------------------------------------------------------------------------ */
|
|
66
|
+
/** Expects the value strictly equal to `false`. */
|
|
67
|
+
toBeFalse() {
|
|
68
|
+
return this._push((e) => e.toBeFalse());
|
|
69
|
+
}
|
|
70
|
+
/* ------------------------------------------------------------------------ */
|
|
71
|
+
/**
|
|
72
|
+
* Expects the value to be _falsy_ (zero, empty string, `false`, ...).
|
|
73
|
+
*
|
|
74
|
+
* Negation: {@link Matchers.toBeTruthy `toBeTruthy()`}
|
|
75
|
+
*/
|
|
76
|
+
toBeFalsy() {
|
|
77
|
+
return this._push((e) => e.toBeFalsy());
|
|
78
|
+
}
|
|
79
|
+
toBeGreaterThan(value) {
|
|
80
|
+
return this._push((e) => e.toBeGreaterThan(value));
|
|
81
|
+
}
|
|
82
|
+
toBeGreaterThanOrEqual(value) {
|
|
83
|
+
return this._push((e) => e.toBeGreaterThanOrEqual(value));
|
|
84
|
+
}
|
|
85
|
+
/* ------------------------------------------------------------------------ */
|
|
86
|
+
/**
|
|
87
|
+
* Expects the value to be an instance of the specified {@link Constructor},
|
|
88
|
+
* and (if specified) further asserts it with an {@link AssertionFunction}.
|
|
89
|
+
*
|
|
90
|
+
* Negation: {@link NegativeMatchers.toBeInstanceOf `not.toInstanceOf(...)`}
|
|
91
|
+
*/
|
|
92
|
+
toBeInstanceOf(constructor, assertion) {
|
|
93
|
+
return this._push((e) => e.toBeInstanceOf(constructor, assertion));
|
|
94
|
+
}
|
|
95
|
+
toBeLessThan(value) {
|
|
96
|
+
return this._push((e) => e.toBeLessThan(value));
|
|
97
|
+
}
|
|
98
|
+
toBeLessThanOrEqual(value) {
|
|
99
|
+
return this._push((e) => e.toBeLessThanOrEqual(value));
|
|
100
|
+
}
|
|
101
|
+
/* ------------------------------------------------------------------------ */
|
|
102
|
+
/**
|
|
103
|
+
* Expects the value to be `NaN`.
|
|
104
|
+
*
|
|
105
|
+
* Negation: {@link NegativeMatchers.toBeNaN `not.toBeNaN()`}
|
|
106
|
+
*/
|
|
107
|
+
toBeNaN() {
|
|
108
|
+
return this._push((e) => e.toBeNaN());
|
|
109
|
+
}
|
|
110
|
+
/* ------------------------------------------------------------------------ */
|
|
111
|
+
/** Expects the value to strictly equal `null`. */
|
|
112
|
+
toBeNull() {
|
|
113
|
+
return this._push((e) => e.toBeNull());
|
|
114
|
+
}
|
|
115
|
+
/* ------------------------------------------------------------------------ */
|
|
116
|
+
/** Expects the value to strictly equal `true`. */
|
|
117
|
+
toBeTrue() {
|
|
118
|
+
return this._push((e) => e.toBeTrue());
|
|
119
|
+
}
|
|
120
|
+
/* ------------------------------------------------------------------------ */
|
|
121
|
+
/**
|
|
122
|
+
* Expects the value to be _falsy_ (non-zero, non-empty string, ...).
|
|
123
|
+
*
|
|
124
|
+
* Negation: {@link Matchers.toBeFalsy `toBeFalsy()`}
|
|
125
|
+
*/
|
|
126
|
+
toBeTruthy() {
|
|
127
|
+
return this._push((e) => e.toBeTruthy());
|
|
128
|
+
}
|
|
129
|
+
/* ------------------------------------------------------------------------ */
|
|
130
|
+
/** Expects the value to strictly equal `undefined`. */
|
|
131
|
+
toBeUndefined() {
|
|
132
|
+
return this._push((e) => e.toBeUndefined());
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Expects the value to be a `number` or `bigint` within the specified range
|
|
136
|
+
* where minimum and maximum values are inclusive.
|
|
137
|
+
*
|
|
138
|
+
* Negation: {@link NegativeMatchers.toBeWithinRange `not.toBeWithinRange(...)`}
|
|
139
|
+
*/
|
|
140
|
+
toBeWithinRange(min, max) {
|
|
141
|
+
return this._push((e) => e.toBeWithinRange(min, max));
|
|
142
|
+
}
|
|
143
|
+
/* ------------------------------------------------------------------------ */
|
|
144
|
+
/**
|
|
145
|
+
* Expects the value to be _deep equal to_ the specified expected one.
|
|
146
|
+
*
|
|
147
|
+
* Negation: {@link NegativeMatchers.toEqual `not.toEqual(...)`}
|
|
148
|
+
*/
|
|
149
|
+
toEqual(expected) {
|
|
150
|
+
return this._push((e) => e.toEqual(expected));
|
|
151
|
+
}
|
|
152
|
+
/* ------------------------------------------------------------------------ */
|
|
153
|
+
/**
|
|
154
|
+
* Expects the value to have a `number` _property_ `length` with the specified
|
|
155
|
+
* expected value.
|
|
156
|
+
*
|
|
157
|
+
* Negation: {@link NegativeMatchers.toHaveLength `not.toHaveLength(...)`}
|
|
158
|
+
*/
|
|
159
|
+
toHaveLength(length) {
|
|
160
|
+
return this._push((e) => e.toHaveLength(length));
|
|
161
|
+
}
|
|
162
|
+
/* ------------------------------------------------------------------------ */
|
|
163
|
+
/**
|
|
164
|
+
* Expects the value to have the specified _property_ and (if specified)
|
|
165
|
+
* further asserts its value with an {@link AssertionFunction}.
|
|
166
|
+
*
|
|
167
|
+
* Negation: {@link NegativeMatchers.toHaveProperty `not.toHaveProperty(...)`}
|
|
168
|
+
*/
|
|
169
|
+
toHaveProperty(property, assertion) {
|
|
170
|
+
return this._push((e) => e.toHaveProperty(property, assertion));
|
|
171
|
+
}
|
|
172
|
+
/* ------------------------------------------------------------------------ */
|
|
173
|
+
/**
|
|
174
|
+
* Expects the value to have a `number` _property_ `size` with the specified
|
|
175
|
+
* expected value.
|
|
176
|
+
*
|
|
177
|
+
* Negation: {@link NegativeMatchers.toHaveSize `not.toHaveSize(...)`}
|
|
178
|
+
*/
|
|
179
|
+
toHaveSize(size) {
|
|
180
|
+
return this._push((e) => e.toHaveSize(size));
|
|
181
|
+
}
|
|
182
|
+
toInclude(contents) {
|
|
183
|
+
return this._push((e) => e.toInclude(contents));
|
|
184
|
+
}
|
|
185
|
+
/* ------------------------------------------------------------------------ */
|
|
186
|
+
/**
|
|
187
|
+
* Expects the value to be a `string` _matching_ the specified sub-`string`
|
|
188
|
+
* or {@link RegExp}.
|
|
189
|
+
*
|
|
190
|
+
* Negation: {@link NegativeMatchers.toMatch `not.toMatch(...)`}
|
|
191
|
+
*/
|
|
192
|
+
toMatch(matcher) {
|
|
193
|
+
return this._push((e) => e.toMatch(matcher));
|
|
194
|
+
}
|
|
195
|
+
toMatchContents(contents) {
|
|
196
|
+
return this._push((e) => e.toMatchContents(contents));
|
|
197
|
+
}
|
|
198
|
+
/* ------------------------------------------------------------------------ */
|
|
199
|
+
/**
|
|
200
|
+
* Expects the value to be _strictly equal to_ the specified expected one.
|
|
201
|
+
*
|
|
202
|
+
* Negation: {@link NegativeMatchers.toStrictlyEqual `not.toStrictlyEqual(...)`}
|
|
203
|
+
*/
|
|
204
|
+
toStrictlyEqual(expected) {
|
|
205
|
+
return this._push((e) => e.toStrictlyEqual(expected));
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var NegativeMatchers = class {
|
|
209
|
+
constructor(_instance, _matchers) {
|
|
210
|
+
this._instance = _instance;
|
|
211
|
+
this._matchers = _matchers;
|
|
212
|
+
}
|
|
213
|
+
_push(matcher) {
|
|
214
|
+
this._matchers.push((expectations) => matcher(expectations.not));
|
|
215
|
+
return this._instance;
|
|
216
|
+
}
|
|
217
|
+
/* ------------------------------------------------------------------------ */
|
|
218
|
+
/**
|
|
219
|
+
* Expects the value _**NOT**_ to be of the specified _extended_
|
|
220
|
+
* {@link TypeName type}.
|
|
221
|
+
*
|
|
222
|
+
* Negates: {@link Matchers.toBeA `toBeA(...)`}
|
|
223
|
+
*/
|
|
224
|
+
toBeA(type) {
|
|
225
|
+
return this._push((e) => e.toBeA(type));
|
|
226
|
+
}
|
|
227
|
+
toBeCloseTo(value, delta) {
|
|
228
|
+
return this._push((e) => e.toBeCloseTo(value, delta));
|
|
229
|
+
}
|
|
230
|
+
/* ------------------------------------------------------------------------ */
|
|
231
|
+
/**
|
|
232
|
+
* Expects the value to be either `null` or `undefined`.
|
|
233
|
+
*
|
|
234
|
+
* Negates: {@link Matchers.toBeDefined `toBeDefined()`}
|
|
235
|
+
*/
|
|
236
|
+
toBeDefined() {
|
|
237
|
+
return this._push((e) => e.toBeDefined());
|
|
238
|
+
}
|
|
239
|
+
/* ------------------------------------------------------------------------ */
|
|
240
|
+
/**
|
|
241
|
+
* Expects the value _**NOT**_ to be an instance of the specified
|
|
242
|
+
* {@link Constructor}.
|
|
243
|
+
*
|
|
244
|
+
* Negates: {@link Matchers.toBeInstanceOf `toBeInstanceOf(...)`}
|
|
245
|
+
*/
|
|
246
|
+
toBeInstanceOf(constructor) {
|
|
247
|
+
return this._push((e) => e.toBeInstanceOf(constructor));
|
|
248
|
+
}
|
|
249
|
+
/* ------------------------------------------------------------------------ */
|
|
250
|
+
/**
|
|
251
|
+
* Expects the value _**NOT**_ to be `NaN`.
|
|
252
|
+
*
|
|
253
|
+
* Negates: {@link Matchers.toBeNaN `toBeNaN()`}
|
|
254
|
+
*/
|
|
255
|
+
toBeNaN() {
|
|
256
|
+
return this._push((e) => e.toBeNaN());
|
|
257
|
+
}
|
|
258
|
+
toBeWithinRange(min, max) {
|
|
259
|
+
return this._push((e) => e.toBeWithinRange(min, max));
|
|
260
|
+
}
|
|
261
|
+
/* ------------------------------------------------------------------------ */
|
|
262
|
+
/**
|
|
263
|
+
* Expects the value _**NOT**_ to be _deep equal to_ the specified expected
|
|
264
|
+
* one.
|
|
265
|
+
*
|
|
266
|
+
* Negates: {@link Matchers.toEqual `toEqual(...)`}
|
|
267
|
+
*/
|
|
268
|
+
toEqual(expected) {
|
|
269
|
+
return this._push((e) => e.toEqual(expected));
|
|
270
|
+
}
|
|
271
|
+
/* ------------------------------------------------------------------------ */
|
|
272
|
+
/**
|
|
273
|
+
* Expects the value to have a `number` _property_ `length` _different_ from
|
|
274
|
+
* the specified expected value.
|
|
275
|
+
*
|
|
276
|
+
* Negates: {@link Matchers.toHaveLength `toHaveLength(...)`}
|
|
277
|
+
*/
|
|
278
|
+
toHaveLength(length) {
|
|
279
|
+
return this._push((e) => e.toHaveLength(length));
|
|
280
|
+
}
|
|
281
|
+
/* ------------------------------------------------------------------------ */
|
|
282
|
+
/**
|
|
283
|
+
* Expects the value _**NOT**_ to have the specified _property_.
|
|
284
|
+
*
|
|
285
|
+
* Negates: {@link Matchers.toHaveProperty `toHaveProperty(...)`}
|
|
286
|
+
*/
|
|
287
|
+
toHaveProperty(property) {
|
|
288
|
+
return this._push((e) => e.toHaveProperty(property));
|
|
289
|
+
}
|
|
290
|
+
/* ------------------------------------------------------------------------ */
|
|
291
|
+
/**
|
|
292
|
+
* Expects the value to have a `number` _property_ `size` _different_ from
|
|
293
|
+
* the specified expected value.
|
|
294
|
+
*
|
|
295
|
+
* Negates: {@link Matchers.toHaveSize `toHaveSize(...)`}
|
|
296
|
+
*/
|
|
297
|
+
toHaveSize(size) {
|
|
298
|
+
return this._push((e) => e.toHaveSize(size));
|
|
299
|
+
}
|
|
300
|
+
toInclude(contents) {
|
|
301
|
+
return this._push((e) => e.toInclude(contents));
|
|
302
|
+
}
|
|
303
|
+
/* ------------------------------------------------------------------------ */
|
|
304
|
+
/**
|
|
305
|
+
* Expects the value to be a `string` _**NOT MATCHING**_ the specified
|
|
306
|
+
* sub-`string` or {@link RegExp}.
|
|
307
|
+
*
|
|
308
|
+
* Negates: {@link Matchers.toMatch `toMatch(...)`}
|
|
309
|
+
*/
|
|
310
|
+
toMatch(matcher) {
|
|
311
|
+
return this._push((e) => e.toMatch(matcher));
|
|
312
|
+
}
|
|
313
|
+
/* ------------------------------------------------------------------------ */
|
|
314
|
+
/**
|
|
315
|
+
* Expects the value _**NOT**_ to be _strictly equal to_ the specified
|
|
316
|
+
* expected one.
|
|
317
|
+
*
|
|
318
|
+
* Negates: {@link Matchers.toStrictlyEqual `toStrictlyEqual(...)`}
|
|
319
|
+
*/
|
|
320
|
+
toStrictlyEqual(expected) {
|
|
321
|
+
return this._push((e) => e.toStrictlyEqual(expected));
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
export {
|
|
325
|
+
Matchers,
|
|
326
|
+
NegativeMatchers
|
|
327
|
+
};
|
|
328
|
+
//# sourceMappingURL=matchers.mjs.map
|