@plugjs/expect5 0.4.3 → 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.
Files changed (90) hide show
  1. package/dist/cli.mjs +2 -2
  2. package/dist/cli.mjs.map +1 -1
  3. package/dist/execution/executor.cjs.map +1 -1
  4. package/dist/execution/executor.d.ts +1 -1
  5. package/dist/execution/executor.mjs +1 -1
  6. package/dist/execution/executor.mjs.map +1 -1
  7. package/dist/execution/setup.cjs.map +1 -1
  8. package/dist/execution/setup.d.ts +1 -1
  9. package/dist/execution/setup.mjs +1 -1
  10. package/dist/execution/setup.mjs.map +1 -1
  11. package/dist/expectation/async.cjs +58 -45
  12. package/dist/expectation/async.cjs.map +1 -1
  13. package/dist/expectation/async.d.ts +53 -52
  14. package/dist/expectation/async.mjs +59 -42
  15. package/dist/expectation/async.mjs.map +1 -1
  16. package/dist/expectation/diff.cjs.map +1 -1
  17. package/dist/expectation/diff.mjs +6 -1
  18. package/dist/expectation/diff.mjs.map +1 -1
  19. package/dist/expectation/expect.cjs +11 -165
  20. package/dist/expectation/expect.cjs.map +2 -2
  21. package/dist/expectation/expect.d.ts +10 -112
  22. package/dist/expectation/expect.mjs +12 -207
  23. package/dist/expectation/expect.mjs.map +2 -2
  24. package/dist/expectation/expectations.cjs +549 -0
  25. package/dist/expectation/expectations.cjs.map +6 -0
  26. package/dist/expectation/expectations.d.ts +454 -0
  27. package/dist/expectation/expectations.mjs +530 -0
  28. package/dist/expectation/expectations.mjs.map +6 -0
  29. package/dist/expectation/include.cjs +43 -41
  30. package/dist/expectation/include.cjs.map +1 -1
  31. package/dist/expectation/include.d.ts +3 -19
  32. package/dist/expectation/include.mjs +43 -41
  33. package/dist/expectation/include.mjs.map +1 -1
  34. package/dist/expectation/matchers.cjs +350 -0
  35. package/dist/expectation/matchers.cjs.map +6 -0
  36. package/dist/expectation/matchers.d.ts +375 -0
  37. package/dist/expectation/matchers.mjs +328 -0
  38. package/dist/expectation/matchers.mjs.map +6 -0
  39. package/dist/expectation/print.cjs.map +1 -1
  40. package/dist/expectation/print.d.ts +2 -2
  41. package/dist/expectation/print.mjs.map +1 -1
  42. package/dist/expectation/types.cjs +17 -23
  43. package/dist/expectation/types.cjs.map +1 -1
  44. package/dist/expectation/types.d.ts +7 -51
  45. package/dist/expectation/types.mjs +17 -22
  46. package/dist/expectation/types.mjs.map +1 -1
  47. package/dist/globals.d.ts +2 -2
  48. package/dist/index.cjs +5 -5
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.ts +3 -4
  51. package/dist/index.mjs +11 -12
  52. package/dist/index.mjs.map +1 -1
  53. package/dist/test.cjs +34 -5
  54. package/dist/test.cjs.map +1 -1
  55. package/dist/test.d.ts +2 -2
  56. package/dist/test.mjs +35 -6
  57. package/dist/test.mjs.map +1 -1
  58. package/package.json +2 -2
  59. package/src/cli.mts +1 -1
  60. package/src/execution/executor.ts +1 -3
  61. package/src/execution/setup.ts +1 -3
  62. package/src/expectation/async.ts +116 -145
  63. package/src/expectation/diff.ts +7 -3
  64. package/src/expectation/expect.ts +22 -362
  65. package/src/expectation/expectations.ts +971 -0
  66. package/src/expectation/include.ts +59 -75
  67. package/src/expectation/matchers.ts +698 -0
  68. package/src/expectation/print.ts +8 -4
  69. package/src/expectation/types.ts +22 -94
  70. package/src/globals.ts +2 -2
  71. package/src/index.ts +17 -10
  72. package/src/test.ts +34 -10
  73. package/dist/expectation/basic.cjs +0 -188
  74. package/dist/expectation/basic.cjs.map +0 -6
  75. package/dist/expectation/basic.d.ts +0 -90
  76. package/dist/expectation/basic.mjs +0 -156
  77. package/dist/expectation/basic.mjs.map +0 -6
  78. package/dist/expectation/throwing.cjs +0 -58
  79. package/dist/expectation/throwing.cjs.map +0 -6
  80. package/dist/expectation/throwing.d.ts +0 -36
  81. package/dist/expectation/throwing.mjs +0 -32
  82. package/dist/expectation/throwing.mjs.map +0 -6
  83. package/dist/expectation/trivial.cjs +0 -96
  84. package/dist/expectation/trivial.cjs.map +0 -6
  85. package/dist/expectation/trivial.d.ts +0 -13
  86. package/dist/expectation/trivial.mjs +0 -61
  87. package/dist/expectation/trivial.mjs.map +0 -6
  88. package/src/expectation/basic.ts +0 -409
  89. package/src/expectation/throwing.ts +0 -106
  90. package/src/expectation/trivial.ts +0 -107
@@ -0,0 +1,530 @@
1
+ // expectation/expectations.ts
2
+ import { diff } from "./diff.mjs";
3
+ import { toInclude, toMatchContents } from "./include.mjs";
4
+ import {
5
+ ExpectationError,
6
+ isMatcher,
7
+ prefixType,
8
+ stringifyConstructor,
9
+ stringifyValue,
10
+ typeOf
11
+ } from "./types.mjs";
12
+ var Expectations = class {
13
+ /**
14
+ * Create an {@link Expectations} instance associated with the specified
15
+ * value and error remarks.
16
+ *
17
+ * Optionally a parent {@link Expectations} instance can be specified.
18
+ */
19
+ constructor(value, remarks, parent) {
20
+ this.value = value;
21
+ this.remarks = remarks;
22
+ this.parent = parent;
23
+ this.not = new NegativeExpectations(this);
24
+ }
25
+ /** The {@link NegativeExpectations} associated with _this_ */
26
+ not;
27
+ /** Throw an {@link ExpectationError} associated with _this_ */
28
+ _fail(details, diff2) {
29
+ throw new ExpectationError(this, details, diff2);
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 NegativeExpectations.toBeA `not.toBeA(...)`}
39
+ */
40
+ toBeA(type, assertion) {
41
+ if (typeOf(this.value) === type) {
42
+ if (assertion)
43
+ assertion(this);
44
+ return this;
45
+ }
46
+ this._fail(`to be ${prefixType(type)}`);
47
+ }
48
+ toBeCloseTo(value, delta) {
49
+ const min = value - delta;
50
+ const max = value + delta;
51
+ return this.toBeWithinRange(min, max);
52
+ }
53
+ /* ------------------------------------------------------------------------ */
54
+ /**
55
+ * Expects the value to be neither `null` nor `undefined`.
56
+ *
57
+ * Negation: {@link NegativeExpectations.toBeDefined `not.toBeDefined()`}
58
+ */
59
+ toBeDefined() {
60
+ if (this.value !== null && this.value !== void 0)
61
+ return this;
62
+ this._fail(`to be neither ${stringifyValue(null)} nor ${stringifyValue(void 0)}`);
63
+ }
64
+ toBeError(constructorOrMessage, maybeMessage) {
65
+ const [constructor, message] = typeof constructorOrMessage === "function" ? [constructorOrMessage, maybeMessage] : [Error, constructorOrMessage];
66
+ if (message === void 0)
67
+ return this.toBeInstanceOf(constructor);
68
+ return this.toBeInstanceOf(constructor, (assert) => {
69
+ assert.toHaveProperty("message", (assertMessage) => {
70
+ assertMessage.toBeA("string");
71
+ if (typeof message === "string")
72
+ assertMessage.toStrictlyEqual(message);
73
+ else
74
+ assertMessage.toMatch(message);
75
+ });
76
+ });
77
+ }
78
+ /* ------------------------------------------------------------------------ */
79
+ /** Expects the value strictly equal to `false`. */
80
+ toBeFalse() {
81
+ return this.toStrictlyEqual(false);
82
+ }
83
+ /* ------------------------------------------------------------------------ */
84
+ /**
85
+ * Expects the value to be _falsy_ (zero, empty string, `false`, ...).
86
+ *
87
+ * Negation: {@link Expectations.toBeTruthy `toBeTruthy()`}
88
+ */
89
+ toBeFalsy() {
90
+ if (!this.value)
91
+ return this;
92
+ this._fail("to be falsy");
93
+ }
94
+ toBeGreaterThan(value) {
95
+ this.toBeA(typeof value);
96
+ if (this.value > value)
97
+ return this;
98
+ this._fail(`to be greater than ${stringifyValue(value)}`);
99
+ }
100
+ toBeGreaterThanOrEqual(value) {
101
+ this.toBeA(typeof value);
102
+ if (this.value >= value)
103
+ return this;
104
+ this._fail(`to be greater than or equal to ${stringifyValue(value)}`);
105
+ }
106
+ /* ------------------------------------------------------------------------ */
107
+ /**
108
+ * Expects the value to be an instance of the specified {@link Constructor},
109
+ * and (if specified) further asserts it with an {@link AssertionFunction}.
110
+ *
111
+ * Negation: {@link NegativeExpectations.toBeInstanceOf `not.toInstanceOf(...)`}
112
+ */
113
+ toBeInstanceOf(constructor, assertion) {
114
+ if (this.value instanceof constructor) {
115
+ if (assertion)
116
+ assertion(this);
117
+ return this;
118
+ }
119
+ this._fail(`to be an instance of ${stringifyConstructor(constructor)}`);
120
+ }
121
+ toBeLessThan(value) {
122
+ this.toBeA(typeof value);
123
+ if (this.value < value)
124
+ return this;
125
+ this._fail(`to be less than ${stringifyValue(value)}`);
126
+ }
127
+ toBeLessThanOrEqual(value) {
128
+ this.toBeA(typeof value);
129
+ if (this.value <= value)
130
+ return this;
131
+ this._fail(`to be less than or equal to ${stringifyValue(value)}`);
132
+ }
133
+ /* ------------------------------------------------------------------------ */
134
+ /**
135
+ * Expects the value to be `NaN`.
136
+ *
137
+ * Negation: {@link NegativeExpectations.toBeNaN `not.toBeNaN()`}
138
+ */
139
+ toBeNaN() {
140
+ const expectations = this.toBeA("number");
141
+ if (isNaN(expectations.value))
142
+ return expectations;
143
+ this._fail(`to be ${stringifyValue(NaN)}`);
144
+ }
145
+ /* ------------------------------------------------------------------------ */
146
+ /** Expects the value to strictly equal `null`. */
147
+ toBeNull() {
148
+ return this.toStrictlyEqual(null);
149
+ }
150
+ /* ------------------------------------------------------------------------ */
151
+ /** Expects the value to strictly equal `true`. */
152
+ toBeTrue() {
153
+ return this.toStrictlyEqual(true);
154
+ }
155
+ /* ------------------------------------------------------------------------ */
156
+ /**
157
+ * Expects the value to be _falsy_ (non-zero, non-empty string, ...).
158
+ *
159
+ * Negation: {@link Expectations.toBeFalsy `toBeFalsy()`}
160
+ */
161
+ toBeTruthy() {
162
+ if (this.value)
163
+ return this;
164
+ this._fail("to be truthy");
165
+ }
166
+ /* ------------------------------------------------------------------------ */
167
+ /** Expects the value to strictly equal `undefined`. */
168
+ toBeUndefined() {
169
+ return this.toStrictlyEqual(void 0);
170
+ }
171
+ toBeWithinRange(min, max) {
172
+ if (max < min) {
173
+ const num = max;
174
+ max = min;
175
+ min = num;
176
+ }
177
+ this.toBeA(typeof min);
178
+ if (this.value < min || this.value > max) {
179
+ this._fail(`to be within ${stringifyValue(min)}...${stringifyValue(max)}`);
180
+ }
181
+ return this;
182
+ }
183
+ /* ------------------------------------------------------------------------ */
184
+ /**
185
+ * Expects the value to be _deep equal to_ the specified expected one.
186
+ *
187
+ * Negation: {@link NegativeExpectations.toEqual `not.toEqual(...)`}
188
+ */
189
+ toEqual(expected) {
190
+ if (this.value === expected)
191
+ return this;
192
+ const result = diff(this.value, expected);
193
+ if (result.diff) {
194
+ if (isMatcher(expected)) {
195
+ this._fail("to satisfy expectation matcher", result);
196
+ } else {
197
+ this._fail(`to equal ${stringifyValue(expected)}`, result);
198
+ }
199
+ } else {
200
+ return this;
201
+ }
202
+ }
203
+ /* ------------------------------------------------------------------------ */
204
+ /**
205
+ * Expects the value to have a `number` _property_ `length` with the specified
206
+ * expected value.
207
+ *
208
+ * Negation: {@link NegativeExpectations.toHaveLength `not.toHaveLength(...)`}
209
+ */
210
+ toHaveLength(length) {
211
+ this.toBeDefined();
212
+ const realLength = this.value["length"];
213
+ if (typeof realLength !== "number") {
214
+ this._fail('to have a numeric "length" property');
215
+ } else if (realLength !== length) {
216
+ this._fail(`to have length ${length}`);
217
+ }
218
+ return this;
219
+ }
220
+ /* ------------------------------------------------------------------------ */
221
+ /**
222
+ * Expects the value to have the specified _property_ and (if specified)
223
+ * further asserts its value with an {@link AssertionFunction}.
224
+ *
225
+ * Negation: {@link NegativeExpectations.toHaveProperty `not.toHaveProperty(...)`}
226
+ */
227
+ toHaveProperty(property, assertion) {
228
+ this.toBeDefined();
229
+ const propertyValue = this.value[property];
230
+ if (propertyValue === void 0) {
231
+ this._fail(`to have property "${String(property)}"`);
232
+ }
233
+ if (assertion) {
234
+ try {
235
+ const parent = { expectations: this, prop: property };
236
+ const expectations = new Expectations(propertyValue, this.remarks, parent);
237
+ assertion(expectations);
238
+ } catch (error) {
239
+ if (error instanceof ExpectationError && error.diff) {
240
+ error.diff = {
241
+ diff: true,
242
+ value: this.value,
243
+ props: { [property]: error.diff }
244
+ };
245
+ }
246
+ throw error;
247
+ }
248
+ }
249
+ return this;
250
+ }
251
+ /* ------------------------------------------------------------------------ */
252
+ /**
253
+ * Expects the value to have a `number` _property_ `size` with the specified
254
+ * expected value.
255
+ *
256
+ * Negation: {@link NegativeExpectations.toHaveSize `not.toHaveSize(...)`}
257
+ */
258
+ toHaveSize(size) {
259
+ this.toBeDefined();
260
+ const realSize = this.value["size"];
261
+ if (typeof realSize !== "number") {
262
+ this._fail('to have a numeric "size" property');
263
+ } else if (realSize !== size) {
264
+ this._fail(`to have size ${size}`);
265
+ }
266
+ return this;
267
+ }
268
+ toInclude(contents) {
269
+ toInclude(this, false, contents);
270
+ return this;
271
+ }
272
+ /* ------------------------------------------------------------------------ */
273
+ /**
274
+ * Expects the value to be a `string` _matching_ the specified sub-`string`
275
+ * or {@link RegExp}.
276
+ *
277
+ * Negation: {@link NegativeExpectations.toMatch `not.toMatch(...)`}
278
+ */
279
+ toMatch(matcher) {
280
+ const expectations = this.toBeA("string");
281
+ if (expectations.value.match(matcher))
282
+ return expectations;
283
+ this._fail(`to match ${stringifyValue(matcher)}`);
284
+ }
285
+ /* ------------------------------------------------------------------------ */
286
+ /**
287
+ * Expect the value to be an {@link Iterable} object includind _all_ values
288
+ * (and only those values) from the specified _array_ or {@link Set},
289
+ * in any order.
290
+ */
291
+ toMatchContents(contents) {
292
+ toMatchContents(this, contents);
293
+ return this;
294
+ }
295
+ /* ------------------------------------------------------------------------ */
296
+ /**
297
+ * Expects the value to be _strictly equal to_ the specified expected one.
298
+ *
299
+ * Negation: {@link NegativeExpectations.toStrictlyEqual `not.toStrictlyEqual(...)`}
300
+ */
301
+ toStrictlyEqual(expected) {
302
+ if (this.value === expected)
303
+ return this;
304
+ const diff2 = { diff: true, value: this.value, expected };
305
+ this._fail(`to strictly equal ${stringifyValue(expected)}`, diff2);
306
+ }
307
+ /* ------------------------------------------------------------------------ */
308
+ /**
309
+ * Expects the value to be a `function` throwing, and (if specified) further
310
+ * asserts the thrown value with an {@link AssertionFunction}.
311
+ *
312
+ * Negation: {@link NegativeExpectations.toThrow `not.toThrow()`}
313
+ */
314
+ toThrow(assert) {
315
+ const func = this.toBeA("function");
316
+ let passed = false;
317
+ try {
318
+ func.value();
319
+ passed = true;
320
+ } catch (thrown) {
321
+ if (assert)
322
+ assert(new Expectations(thrown, this.remarks));
323
+ }
324
+ if (passed)
325
+ this._fail("to throw");
326
+ return this;
327
+ }
328
+ toThrowError(constructorOrMessage, maybeMessage) {
329
+ const [constructor, message] = typeof constructorOrMessage === "function" ? [constructorOrMessage, maybeMessage] : [Error, constructorOrMessage];
330
+ return this.toThrow((assert) => assert.toBeError(constructor, message));
331
+ }
332
+ };
333
+ var NegativeExpectations = class {
334
+ /**
335
+ * Create a {@link NegativeExpectations} instance associated with the
336
+ * specified (positive) {@link Expectations}.
337
+ */
338
+ constructor(_expectations) {
339
+ this._expectations = _expectations;
340
+ this._value = _expectations.value;
341
+ }
342
+ /** For convenience, the value associated with the {@link Expectations} */
343
+ _value;
344
+ /** Throw an {@link ExpectationError} associated with _this_ */
345
+ _fail(details, diff2) {
346
+ throw new ExpectationError(this._expectations, details, diff2);
347
+ }
348
+ /* ------------------------------------------------------------------------ */
349
+ /**
350
+ * Expects the value _**NOT**_ to be of the specified _extended_
351
+ * {@link TypeName type}.
352
+ *
353
+ * Negates: {@link Expectations.toBeA `toBeA(...)`}
354
+ */
355
+ toBeA(type) {
356
+ if (typeOf(this._value) !== type)
357
+ return this._expectations;
358
+ this._fail(`not to be ${prefixType(type)}`);
359
+ }
360
+ toBeCloseTo(value, delta) {
361
+ const min = value - delta;
362
+ const max = value + delta;
363
+ return this.toBeWithinRange(min, max);
364
+ }
365
+ /* ------------------------------------------------------------------------ */
366
+ /**
367
+ * Expects the value to be either `null` or `undefined`.
368
+ *
369
+ * Negates: {@link Expectations.toBeDefined `toBeDefined()`}
370
+ */
371
+ toBeDefined() {
372
+ if (this._value === null || this._value === void 0) {
373
+ return this._expectations;
374
+ }
375
+ this._fail(`to be ${stringifyValue(null)} or ${stringifyValue(void 0)}`);
376
+ }
377
+ /* ------------------------------------------------------------------------ */
378
+ /**
379
+ * Expects the value _**NOT**_ to be an instance of the specified
380
+ * {@link Constructor}.
381
+ *
382
+ * Negates: {@link Expectations.toBeInstanceOf `toBeInstanceOf(...)`}
383
+ */
384
+ toBeInstanceOf(constructor) {
385
+ if (this._value instanceof constructor) {
386
+ this._fail(`not to be an instance of ${stringifyConstructor(constructor)}`);
387
+ }
388
+ return this._expectations;
389
+ }
390
+ /* ------------------------------------------------------------------------ */
391
+ /**
392
+ * Expects the value _**NOT**_ to be `NaN`.
393
+ *
394
+ * Negates: {@link Expectations.toBeNaN `toBeNaN()`}
395
+ */
396
+ toBeNaN() {
397
+ const expectations = this._expectations.toBeA("number");
398
+ if (isNaN(expectations.value))
399
+ this._fail(`not to be ${stringifyValue(NaN)}`);
400
+ return expectations;
401
+ }
402
+ toBeWithinRange(min, max) {
403
+ if (max < min) {
404
+ const num = max;
405
+ max = min;
406
+ min = num;
407
+ }
408
+ this._expectations.toBeA(typeof min);
409
+ if (this._value >= min && this._value <= max) {
410
+ this._fail(`not to be within ${stringifyValue(min)}...${stringifyValue(max)}`);
411
+ }
412
+ return this._expectations;
413
+ }
414
+ /* ------------------------------------------------------------------------ */
415
+ /**
416
+ * Expects the value _**NOT**_ to be _deep equal to_ the specified expected
417
+ * one.
418
+ *
419
+ * Negates: {@link Expectations.toEqual `toEqual(...)`}
420
+ */
421
+ toEqual(expected) {
422
+ let result = { diff: false, value: this._value };
423
+ if (this._value !== expected) {
424
+ result = diff(this._value, expected);
425
+ if (result.diff)
426
+ return this._expectations;
427
+ }
428
+ if (isMatcher(expected)) {
429
+ this._fail("not to satisfy expectation matcher", result);
430
+ } else {
431
+ this._fail(`not to equal ${stringifyValue(expected)}`, result);
432
+ }
433
+ }
434
+ /* ------------------------------------------------------------------------ */
435
+ /**
436
+ * Expects the value to have a `number` _property_ `length` _different_ from
437
+ * the specified expected value.
438
+ *
439
+ * Negates: {@link Expectations.toHaveLength `toHaveLength(...)`}
440
+ */
441
+ toHaveLength(length) {
442
+ this._expectations.toBeDefined();
443
+ const realLength = this._value["length"];
444
+ if (typeof realLength !== "number") {
445
+ this._fail('to have a numeric "length" property');
446
+ } else if (realLength === length) {
447
+ this._fail(`not to have length ${length}`);
448
+ }
449
+ return this._expectations;
450
+ }
451
+ /* ------------------------------------------------------------------------ */
452
+ /**
453
+ * Expects the value _**NOT**_ to have the specified _property_.
454
+ *
455
+ * Negates: {@link Expectations.toHaveProperty `toHaveProperty(...)`}
456
+ */
457
+ toHaveProperty(property) {
458
+ this._expectations.toBeDefined();
459
+ const propertyValue = this._value[property];
460
+ if (propertyValue === void 0)
461
+ return this._expectations;
462
+ this._fail(`not to have property "${String(property)}"`);
463
+ }
464
+ /* ------------------------------------------------------------------------ */
465
+ /**
466
+ * Expects the value to have a `number` _property_ `size` _different_ from
467
+ * the specified expected value.
468
+ *
469
+ * Negates: {@link Expectations.toHaveSize `toHaveSize(...)`}
470
+ */
471
+ toHaveSize(size) {
472
+ this._expectations.toBeDefined();
473
+ const realSize = this._value["size"];
474
+ if (typeof realSize !== "number") {
475
+ this._fail('to have a numeric "size" property');
476
+ } else if (realSize === size) {
477
+ this._fail(`not to have size ${size}`);
478
+ }
479
+ return this._expectations;
480
+ }
481
+ toInclude(contents) {
482
+ toInclude(this._expectations, true, contents);
483
+ return this._expectations;
484
+ }
485
+ /* ------------------------------------------------------------------------ */
486
+ /**
487
+ * Expects the value to be a `string` _**NOT MATCHING**_ the specified
488
+ * sub-`string` or {@link RegExp}.
489
+ *
490
+ * Negates: {@link Expectations.toMatch `toMatch(...)`}
491
+ */
492
+ toMatch(matcher) {
493
+ const expectations = this._expectations.toBeA("string");
494
+ if (!expectations.value.match(matcher))
495
+ return expectations;
496
+ this._fail(`not to match ${stringifyValue(matcher)}`);
497
+ }
498
+ /* ------------------------------------------------------------------------ */
499
+ /**
500
+ * Expects the value to be a `function` not throwing anything.
501
+ *
502
+ * Negates: {@link Expectations.toThrow `toThrow(...)`}
503
+ */
504
+ toThrow() {
505
+ const expectations = this._expectations.toBeA("function");
506
+ try {
507
+ expectations.value();
508
+ return expectations;
509
+ } catch (caught) {
510
+ this._fail("not to throw");
511
+ }
512
+ }
513
+ /* ------------------------------------------------------------------------ */
514
+ /**
515
+ * Expects the value _**NOT**_ to be _strictly equal to_ the specified
516
+ * expected one.
517
+ *
518
+ * Negates: {@link Expectations.toStrictlyEqual `toStrictlyEqual(...)`}
519
+ */
520
+ toStrictlyEqual(expected) {
521
+ if (this._value !== expected)
522
+ return this._expectations;
523
+ this._fail(`not to strictly equal ${stringifyValue(expected)}`);
524
+ }
525
+ };
526
+ export {
527
+ Expectations,
528
+ NegativeExpectations
529
+ };
530
+ //# sourceMappingURL=expectations.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/expectation/expectations.ts"],
4
+ "mappings": ";AAAA,SAAS,YAAuB;AAChC,SAAS,WAAW,uBAAuB;AAE3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAmCA,IAAM,eAAN,MAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUrC,YAEa,OAEA,SAKA,QACX;AARW;AAEA;AAKA;AAEX,SAAK,MAAM,IAAI,qBAAqB,IAAI;AAAA,EAC1C;AAAA;AAAA,EApBS;AAAA;AAAA,EAuBC,MAAM,SAAiBA,OAAoB;AACnD,UAAM,IAAI,iBAAiB,MAAM,SAASA,KAAI;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAKI,MACA,WAC0C;AAC5C,QAAI,OAAO,KAAK,KAAK,MAAM,MAAM;AAC/B,UAAI;AAAW,kBAAU,IAAyB;AAClD,aAAO;AAAA,IACT;AAEA,SAAK,MAAM,SAAS,WAAW,IAAI,GAAG;AA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AC1C,SAAK,MAAM,yBAAyB,eAAe,QAAQ,GAAG;AAAA,EAChE;AACF;",
5
+ "names": ["diff"]
6
+ }
@@ -26,45 +26,45 @@ __export(include_exports, {
26
26
  module.exports = __toCommonJS(include_exports);
27
27
  var import_diff = require("./diff.cjs");
28
28
  var import_types = require("./types.cjs");
29
- function toInclude(expected) {
30
- if (expected instanceof Map)
31
- return includesMappings(this, expected);
32
- if (expected instanceof Set)
33
- return includesValues(this, expected);
34
- if (Array.isArray(expected))
35
- return includesValues(this, new Set(expected));
36
- if (expected instanceof Object)
37
- return includesProps(this, expected);
38
- throw new TypeError(`Invalid type for "toInclude(...)": ${(0, import_types.stringifyValue)(expected)}`);
29
+ function toInclude(expectations, negative, contents) {
30
+ if (contents instanceof Map)
31
+ return includesMappings(expectations, negative, contents);
32
+ if (contents instanceof Set)
33
+ return includesValues(expectations, negative, contents);
34
+ if (Array.isArray(contents))
35
+ return includesValues(expectations, negative, new Set(contents));
36
+ if (contents instanceof Object)
37
+ return includesProps(expectations, negative, contents);
38
+ throw new TypeError(`Invalid type for "toInclude(...)": ${(0, import_types.stringifyValue)(contents)}`);
39
39
  }
40
- function toMatchContents(contents) {
40
+ function toMatchContents(expectations, contents) {
41
41
  let actual;
42
42
  let expected;
43
43
  try {
44
- actual = new Set(this.value);
44
+ actual = new Set(expectations.value);
45
45
  expected = new Set(contents);
46
46
  } catch (error) {
47
- throw new import_types.ExpectationError(this, "to be an iterable object", false);
47
+ throw new import_types.ExpectationError(expectations, "to be an iterable object");
48
48
  }
49
49
  const result = (0, import_diff.diff)(actual, expected);
50
50
  delete result.error;
51
- if (result.diff === this.negative)
52
- return this.expects;
51
+ if (!result.diff)
52
+ return;
53
53
  throw new import_types.ExpectationError(
54
- this,
54
+ expectations,
55
55
  `to match contents of ${(0, import_types.stringifyObjectType)(contents)}`,
56
- { ...result, value: this.value }
56
+ { ...result, value: expectations.value }
57
57
  );
58
58
  }
59
- function includesProps(context, expected) {
60
- if (context.value instanceof Map) {
61
- return includesMappings(context, new Map(Object.entries(expected)));
59
+ function includesProps(expectations, negative, expected) {
60
+ if (expectations.value instanceof Map) {
61
+ return includesMappings(expectations, negative, new Map(Object.entries(expected)));
62
62
  }
63
- context.expects.toBeInstanceOf(Object);
64
- const actual = context.value;
63
+ expectations.toBeInstanceOf(Object);
64
+ const actual = expectations.value;
65
65
  const keys = new Set(Object.keys(expected));
66
66
  const props = {};
67
- if (context.negative) {
67
+ if (negative) {
68
68
  for (const key of keys) {
69
69
  if (actual[key] !== void 0 || key in actual) {
70
70
  props[key] = { diff: true, extra: actual[key] };
@@ -86,22 +86,23 @@ function includesProps(context, expected) {
86
86
  }
87
87
  const count = Object.keys(props).length;
88
88
  if (count === 0)
89
- return context.expects;
89
+ return;
90
90
  const type = count === 1 ? "property" : "properties";
91
- throw new import_types.ExpectationError(context, `to include ${count} ${type}`, {
91
+ const not = negative ? "not " : "";
92
+ throw new import_types.ExpectationError(expectations, `${not}to include ${count} ${type}`, {
92
93
  diff: true,
93
94
  value: actual,
94
95
  props
95
96
  });
96
97
  }
97
- function includesValues(context, expected) {
98
- context.expects.toBeInstanceOf(Object);
99
- if (typeof context.value[Symbol.iterator] !== "function") {
100
- throw new import_types.ExpectationError(context, "to be an iterable object", false);
98
+ function includesValues(expectations, negative, expected) {
99
+ expectations.toBeInstanceOf(Object);
100
+ if (typeof expectations.value[Symbol.iterator] !== "function") {
101
+ throw new import_types.ExpectationError(expectations, "to be an iterable object");
101
102
  }
102
- const actual = new Set(context.value);
103
+ const actual = new Set(expectations.value);
103
104
  const values = [];
104
- if (context.negative) {
105
+ if (negative) {
105
106
  for (const exp of expected) {
106
107
  for (const act of actual) {
107
108
  const result = (0, import_diff.diff)(act, exp);
@@ -128,20 +129,20 @@ function includesValues(context, expected) {
128
129
  }
129
130
  const count = values.length;
130
131
  if (count === 0)
131
- return context.expects;
132
+ return;
132
133
  const type = count === 1 ? "value" : "values";
133
- throw new import_types.ExpectationError(context, `to include ${count} ${type}`, {
134
+ const not = negative ? "not " : "";
135
+ throw new import_types.ExpectationError(expectations, `${not}to include ${count} ${type}`, {
134
136
  diff: true,
135
- value: context.value,
137
+ value: expectations.value,
136
138
  values
137
139
  });
138
140
  }
139
- function includesMappings(context, expected) {
140
- context.expects.toBeInstanceOf(Map);
141
- const actual = context.value;
141
+ function includesMappings(expectations, negative, expected) {
142
+ const actual = expectations.toBeInstanceOf(Map).value;
142
143
  const keys = new Set(expected.keys());
143
144
  const mappings = [];
144
- if (context.negative) {
145
+ if (negative) {
145
146
  for (const key of keys) {
146
147
  if (actual.has(key)) {
147
148
  mappings.push([key, { diff: true, extra: actual.get(key) }]);
@@ -160,11 +161,12 @@ function includesMappings(context, expected) {
160
161
  }
161
162
  const count = mappings.length;
162
163
  if (count === 0)
163
- return context.expects;
164
+ return;
164
165
  const type = count === 1 ? "mapping" : "mappings";
165
- throw new import_types.ExpectationError(context, `to include ${count} ${type}`, {
166
+ const not = negative ? "not " : "";
167
+ throw new import_types.ExpectationError(expectations, `${not}to include ${count} ${type}`, {
166
168
  diff: true,
167
- value: context.value,
169
+ value: expectations.value,
168
170
  mappings
169
171
  });
170
172
  }