strong-mock 9.0.0-beta.0 → 9.0.0-beta.2
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/README.md +104 -34
- package/dist/errors/diff.d.ts +4 -0
- package/dist/errors/unexpected-call.d.ts +0 -3
- package/dist/index.js +97 -76
- package/dist/index.js.map +1 -1
- package/dist/matchers/deep-equals.d.ts +2 -2
- package/dist/matchers/is-array.d.ts +1 -1
- package/dist/matchers/is-partial.d.ts +27 -0
- package/dist/matchers/is-plain-object.d.ts +17 -0
- package/dist/matchers/it.d.ts +2 -1
- package/dist/matchers/matcher.d.ts +5 -4
- package/dist/matchers/will-capture.d.ts +2 -2
- package/dist/mock/mock.d.ts +1 -1
- package/dist/mock/stub.d.ts +1 -1
- package/dist/proxy.d.ts +1 -1
- package/dist/verify/verify.d.ts +1 -1
- package/package.json +5 -5
- package/dist/matchers/is-object.d.ts +0 -27
package/README.md
CHANGED
|
@@ -31,6 +31,7 @@ console.log(foo.bar(23)); // 'I am strong!'
|
|
|
31
31
|
- [Type safety](#type-safety)
|
|
32
32
|
- [Matchers](#matchers)
|
|
33
33
|
- [Awesome error messages](#awesome-error-messages)
|
|
34
|
+
- [Works with Promises and Errors](#works-with-promises-and-errors)
|
|
34
35
|
- [Installation](#installation)
|
|
35
36
|
- [Requirements](#requirements)
|
|
36
37
|
- [API](#api)
|
|
@@ -44,19 +45,22 @@ console.log(foo.bar(23)); // 'I am strong!'
|
|
|
44
45
|
- [Verifying expectations](#verifying-expectations)
|
|
45
46
|
- [Resetting expectations](#resetting-expectations)
|
|
46
47
|
- [Matchers](#matchers-1)
|
|
48
|
+
- [Creating your own matcher](#creating-your-own-matcher)
|
|
47
49
|
- [Mock options](#mock-options)
|
|
48
50
|
- [Unexpected property return value](#unexpected-property-return-value)
|
|
49
51
|
- [Exact params](#exact-params)
|
|
50
52
|
- [Concrete matcher](#concrete-matcher)
|
|
51
53
|
- [FAQ](#faq)
|
|
52
54
|
- [Why do I have to set all expectations first?](#why-do-i-have-to-set-all-expectations-first)
|
|
53
|
-
- [Why do I get a `Didn't expect mock to be called` error?](#why-do-i-get-a-didnt-expect-mock-to-be-called-error)
|
|
54
55
|
- [Why do I have to set a return value even if it's `undefined`?](#why-do-i-have-to-set-a-return-value-even-if-its-undefined)
|
|
56
|
+
- [Why do I get a `Didn't expect mock to be called` error?](#why-do-i-get-a-didnt-expect-mock-to-be-called-error)
|
|
55
57
|
- [Can I partially mock a concrete implementation?](#can-i-partially-mock-a-concrete-implementation)
|
|
56
58
|
- [How do I set expectations on setters?](#how-do-i-set-expectations-on-setters)
|
|
57
59
|
- [How do I provide a function for the mock to call?](#how-do-i-provide-a-function-for-the-mock-to-call)
|
|
58
60
|
- [Can I spread or enumerate a mock?](#can-i-spread-or-enumerate-a-mock)
|
|
61
|
+
- [Why does `typeof mock()` return `function`?](#why-does-typeof-mock-return-function)
|
|
59
62
|
- [How can I ignore `undefined` keys when setting expectations on objects?](#how-can-i-ignore-undefined-keys-when-setting-expectations-on-objects)
|
|
63
|
+
- [How can I verify order of calls?](#how-can-i-verify-order-of-calls)
|
|
60
64
|
|
|
61
65
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
62
66
|
|
|
@@ -64,7 +68,7 @@ console.log(foo.bar(23)); // 'I am strong!'
|
|
|
64
68
|
|
|
65
69
|
### Type safety
|
|
66
70
|
|
|
67
|
-
The
|
|
71
|
+
The mocks will share the same types as your production code, and you can safely refactor in an IDE knowing that all usages will be updated.
|
|
68
72
|
|
|
69
73
|

|
|
70
74
|
|
|
@@ -72,7 +76,7 @@ The mock expectations will share the same type guarantees as your production cod
|
|
|
72
76
|
|
|
73
77
|
You can use matchers to partially match values, or create complex expectations, while still maintaining type safety.
|
|
74
78
|
|
|
75
|
-

|
|
76
80
|
|
|
77
81
|
### Awesome error messages
|
|
78
82
|
|
|
@@ -85,7 +89,7 @@ const fn = mock<(pos: { x: number; y: number }) => boolean>();
|
|
|
85
89
|
|
|
86
90
|
when(() =>
|
|
87
91
|
fn(
|
|
88
|
-
It.
|
|
92
|
+
It.isPartial({
|
|
89
93
|
x: It.isNumber(),
|
|
90
94
|
y: It.matches<number>((y) => y > 0)
|
|
91
95
|
})
|
|
@@ -97,6 +101,25 @@ fn({ x: 1, y: -1 });
|
|
|
97
101
|
|
|
98
102
|

|
|
99
103
|
|
|
104
|
+
### Works with Promises and Errors
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { mock, when } from 'strong-mock';
|
|
108
|
+
|
|
109
|
+
const fn = mock<(id: number) => Promise<string>>();
|
|
110
|
+
|
|
111
|
+
when(() => fn(42)).thenResolve('foo');
|
|
112
|
+
when(() => fn(-1)).thenReject('oops');
|
|
113
|
+
|
|
114
|
+
console.log(await fn(42)); // foo
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
await fn(-1);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.log(e.message); // oops
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
100
123
|
## Installation
|
|
101
124
|
|
|
102
125
|
```shell
|
|
@@ -251,10 +274,10 @@ It is recommended that you call `verify()` on your mocks at the end of every tes
|
|
|
251
274
|
```typescript
|
|
252
275
|
afterEach(() => {
|
|
253
276
|
verifyAll();
|
|
254
|
-
})
|
|
277
|
+
});
|
|
255
278
|
```
|
|
256
279
|
|
|
257
|
-

|
|
258
281
|
|
|
259
282
|
### Resetting expectations
|
|
260
283
|
|
|
@@ -275,7 +298,7 @@ If you create common mocks that are shared by multiple tests you should reset th
|
|
|
275
298
|
```typescript
|
|
276
299
|
beforeEach(() => {
|
|
277
300
|
resetAll();
|
|
278
|
-
})
|
|
301
|
+
});
|
|
279
302
|
```
|
|
280
303
|
|
|
281
304
|
### Matchers
|
|
@@ -289,7 +312,7 @@ const fn = mock<
|
|
|
289
312
|
|
|
290
313
|
when(() => fn(
|
|
291
314
|
It.isAny(),
|
|
292
|
-
It.
|
|
315
|
+
It.isPartial({ values: [1, 2, 3] })
|
|
293
316
|
)).thenReturn('matched!');
|
|
294
317
|
|
|
295
318
|
console.log(fn(
|
|
@@ -301,7 +324,7 @@ console.log(fn(
|
|
|
301
324
|
You can mix matchers with concrete arguments:
|
|
302
325
|
|
|
303
326
|
```typescript
|
|
304
|
-
when(() => fn(42, It.
|
|
327
|
+
when(() => fn(42, It.isPlainObject())).thenReturn('matched');
|
|
305
328
|
```
|
|
306
329
|
|
|
307
330
|
Available matchers:
|
|
@@ -311,9 +334,10 @@ Available matchers:
|
|
|
311
334
|
- `isNumber` - matches any number,
|
|
312
335
|
- `isString` - matches any string, can search for substrings and patterns,
|
|
313
336
|
- `isArray` - matches any array, can search for subsets,
|
|
314
|
-
- `
|
|
315
|
-
- `
|
|
316
|
-
- `willCapture` - matches anything and stores the received value
|
|
337
|
+
- `isPlainObject` - matches any plain object,
|
|
338
|
+
- `isPartial` - recursively matches a subset of an object,
|
|
339
|
+
- `willCapture` - matches anything and stores the received value,
|
|
340
|
+
- `matches` - [build your own matcher](#creating-your-own-matcher).
|
|
317
341
|
|
|
318
342
|
The following table illustrates the differences between the equality matchers:
|
|
319
343
|
|
|
@@ -324,27 +348,16 @@ The following table illustrates the differences between the equality matchers:
|
|
|
324
348
|
| `{ }` | `{ foo: undefined }` | not equal | not equal | equal |
|
|
325
349
|
| `new (class {})()` | `new (class {})()` | not equal | not equal | equal |
|
|
326
350
|
|
|
327
|
-
Some matchers, like `
|
|
351
|
+
Some matchers, like `isPartial` and `isArray` support nesting matchers:
|
|
328
352
|
|
|
329
353
|
```typescript
|
|
330
|
-
It.
|
|
354
|
+
It.isPartial({ foo: It.isString() })
|
|
331
355
|
|
|
332
|
-
It.isArray([ It.
|
|
356
|
+
It.isArray([ It.isPartial({
|
|
333
357
|
foo: It.isString({ matching: /foo/ })
|
|
334
358
|
})])
|
|
335
359
|
```
|
|
336
360
|
|
|
337
|
-
You can create arbitrarily complex and type safe matchers with `It.matches(cb)`:
|
|
338
|
-
|
|
339
|
-
```typescript
|
|
340
|
-
const fn = mock<(x: number, y: number[]) => string>();
|
|
341
|
-
|
|
342
|
-
when(() => fn(
|
|
343
|
-
It.matches(x => x > 0),
|
|
344
|
-
It.matches(y => y.includes(42))
|
|
345
|
-
)).thenReturn('matched');
|
|
346
|
-
```
|
|
347
|
-
|
|
348
361
|
`It.willCapture` is a special matcher that will match any value and store it, so you can access it outside an expectation. This could be useful to capture a callback and then test it separately.
|
|
349
362
|
|
|
350
363
|
```ts
|
|
@@ -359,6 +372,57 @@ console.log(fn(23, (x) => x + 1)); // 42
|
|
|
359
372
|
console.log(matcher.value?.(3)); // 4
|
|
360
373
|
```
|
|
361
374
|
|
|
375
|
+
#### Creating your own matcher
|
|
376
|
+
|
|
377
|
+
You can create arbitrarily complex and type safe matchers with `It.matches()`:
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
const fn = mock<(x: number, y: string) => string>();
|
|
381
|
+
|
|
382
|
+
when(() => fn(
|
|
383
|
+
It.matches(x => x > 0),
|
|
384
|
+
It.matches(y => y.startsWith('foo'))
|
|
385
|
+
)).thenReturn('matched');
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
The types are automatically inferred, but you can also specify them explicitly through the generic parameter, which is useful if you want to create reusable matchers:
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
const startsWith = (expected: string) => It.matches<string>(
|
|
392
|
+
actual => actual.startsWith(expected)
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
when(() => fn(42, startsWith('foo'))).thenReturn('matched');
|
|
396
|
+
|
|
397
|
+
fn(42, 'foobar') // 'matched'
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
You can also customize how the matcher is printed in error messages, and how the diff is printed:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const closeTo = (expected: number, precision = 0.01) => It.matches<number>(
|
|
404
|
+
actual => Math.abs(expected - actual) <= precision,
|
|
405
|
+
{
|
|
406
|
+
toString: () => `closeTo(${expected}, ${precision})`,
|
|
407
|
+
getDiff: (actual) => {
|
|
408
|
+
const diff = Math.abs(expected - actual);
|
|
409
|
+
const sign = diff < 0 ? '-' : '+';
|
|
410
|
+
|
|
411
|
+
return {
|
|
412
|
+
actual: `${actual} (${sign}${diff})`,
|
|
413
|
+
expected: `${expected} ±${precision}`,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
when(() => fn(closeTo(1), 'foo')).thenReturn('matched');
|
|
420
|
+
|
|
421
|
+
fn(2, 'foo');
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+

|
|
425
|
+
|
|
362
426
|
## Mock options
|
|
363
427
|
|
|
364
428
|
The following options can be set per mock, or globally with `setDefaults`.
|
|
@@ -470,19 +534,17 @@ This design decision has a few reasons behind it. First, it forces you to be awa
|
|
|
470
534
|
|
|
471
535
|
Secondly, it will highlight potential design problems such as violations of the SOLID principles. If you find yourself duplicating expectations between tests and passing dummy values to them because your test is not concerned with them, then you might want to look into splitting the code to only depend on things it really needs.
|
|
472
536
|
|
|
473
|
-
### Why do I
|
|
537
|
+
### Why do I have to set a return value even if it's `undefined`?
|
|
474
538
|
|
|
475
|
-
|
|
539
|
+
To make side effects explicit and to prevent future refactoring headaches. If you had just `when(() => fn())`, and you later changed `fn()` to return a `number`, then your expectation would become incorrect and the compiler couldn't check that for you.
|
|
476
540
|
|
|
477
|
-
|
|
541
|
+
### Why do I get a `Didn't expect mock to be called` error?
|
|
478
542
|
|
|
479
|
-
|
|
543
|
+
This error happens when your code under test calls a mock that didn't have a matching expectation. It could be that the arguments received didn't match the ones set in the expectation (see [matchers](#matchers-1)), or the call was made more than the allowed number of times (see [invocation count expectations](#setting-invocation-count-expectations)).
|
|
480
544
|
|
|
481
|
-
|
|
545
|
+
In rare cases, the code under test may try to inspect the mock by accessing special properties on it. For instance, wrapping a mock in `Promise.resolve()` will try to access a `.then` property on it. strong-mock returns stub values for most of these, but if you find another one feel free to [open an issue](https://github.com/NiGhTTraX/strong-mock/issues) with a minimal reproduction.
|
|
482
546
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
To make side effects explicit and to prevent future refactoring headaches. If you had just `when(() => fn())`, and you later changed `fn()` to return a `number`, then your expectation would become incorrect and the compiler couldn't check that for you.
|
|
547
|
+
Unfortunately, not all of these cases can be covered with stub values, and you may have to slightly adjust your code to work around this issue.
|
|
486
548
|
|
|
487
549
|
### Can I partially mock a concrete implementation?
|
|
488
550
|
|
|
@@ -526,6 +588,10 @@ console.log(foo2.bar); // 42
|
|
|
526
588
|
console.log(foo2.baz); // undefined
|
|
527
589
|
```
|
|
528
590
|
|
|
591
|
+
### Why does `typeof mock()` return `function`?
|
|
592
|
+
|
|
593
|
+
All mocks and methods on them are functions in order to intercept function calls.
|
|
594
|
+
|
|
529
595
|
### How can I ignore `undefined` keys when setting expectations on objects?
|
|
530
596
|
|
|
531
597
|
Use the `It.deepEquals` matcher explicitly inside `when` and pass `{ strict: false }`:
|
|
@@ -547,3 +613,7 @@ setDefaults({
|
|
|
547
613
|
concreteMatcher: (expected) => It.deepEquals(expected, { strict: false })
|
|
548
614
|
});
|
|
549
615
|
```
|
|
616
|
+
|
|
617
|
+
### How can I verify order of calls?
|
|
618
|
+
|
|
619
|
+
`when()` expectations can be satisfied in any order. If your code under test depends on a specific order of execution, consider redesigning it to remove the coupling before the different calls.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Expectation } from '../expectation/expectation';
|
|
2
|
+
export declare const printArgsDiff: (expected: unknown[], actual: unknown[]) => string;
|
|
3
|
+
export declare const printExpectationDiff: (e: Expectation, args: unknown[]) => string;
|
|
4
|
+
export declare const printDiffForAllExpectations: (expectations: Expectation[], actual: unknown[]) => string;
|
|
@@ -7,9 +7,6 @@ type MatcherResult = {
|
|
|
7
7
|
interface MatcherError {
|
|
8
8
|
matcherResult?: MatcherResult;
|
|
9
9
|
}
|
|
10
|
-
export declare const printArgsDiff: (expected: unknown[], actual: unknown[]) => string;
|
|
11
|
-
export declare const printExpectationDiff: (e: Expectation, args: unknown[]) => string;
|
|
12
|
-
export declare const printDiffForAllExpectations: (expectations: Expectation[], actual: unknown[]) => string;
|
|
13
10
|
export declare class UnexpectedCall extends Error implements MatcherError {
|
|
14
11
|
matcherResult?: MatcherResult;
|
|
15
12
|
constructor(property: Property, args: unknown[], expectations: Expectation[]);
|
package/dist/index.js
CHANGED
|
@@ -234,6 +234,7 @@ ${diff}`;
|
|
|
234
234
|
|
|
235
235
|
return undefined;
|
|
236
236
|
}).filter(x => x).join('\n\n');
|
|
237
|
+
|
|
237
238
|
class UnexpectedCall extends Error {
|
|
238
239
|
constructor(property, args, expectations) {
|
|
239
240
|
const header = `Didn't expect ${printCall(property, args)} to be called.`;
|
|
@@ -708,7 +709,7 @@ const removeUndefined = object => {
|
|
|
708
709
|
* non `Object` instances with different constructors as not equal. Setting
|
|
709
710
|
* this to `false` will consider the objects in both cases as equal.
|
|
710
711
|
*
|
|
711
|
-
* @see {@link It.
|
|
712
|
+
* @see {@link It.isPartial} or {@link It.isArray} if you want to nest matchers.
|
|
712
713
|
* @see {@link It.is} if you want to use strict equality.
|
|
713
714
|
*/
|
|
714
715
|
|
|
@@ -1273,67 +1274,108 @@ const isNumber = () => matches(actual => typeof actual === 'number' && !Number.i
|
|
|
1273
1274
|
})
|
|
1274
1275
|
});
|
|
1275
1276
|
|
|
1276
|
-
|
|
1277
|
+
/**
|
|
1278
|
+
* Matches any plain object e.g. object literals or objects created with `Object.create()`.
|
|
1279
|
+
*
|
|
1280
|
+
* Classes, arrays, maps, sets etc. are not considered plain objects.
|
|
1281
|
+
* You can use {@link isPartial} or {@link matches} to match those.
|
|
1282
|
+
*
|
|
1283
|
+
* @example
|
|
1284
|
+
* const fn = mock<({ foo: string }) => number>();
|
|
1285
|
+
* when(() => fn(It.isPlainObject())).thenReturn(42);
|
|
1286
|
+
*
|
|
1287
|
+
* fn({ foo: 'bar' }) // returns 42
|
|
1288
|
+
*/
|
|
1277
1289
|
|
|
1278
|
-
const
|
|
1279
|
-
|
|
1290
|
+
const isPlainObject = () => matches(actual => lodash.isPlainObject(actual), {
|
|
1291
|
+
toString: () => 'Matcher<object>',
|
|
1292
|
+
getDiff: actual => {
|
|
1293
|
+
const type = lodash.isObjectLike(actual) ? 'object-like' : typeof actual;
|
|
1294
|
+
return {
|
|
1295
|
+
actual: `${printValue(actual)} (${type})`,
|
|
1296
|
+
expected: 'Matcher<object>'
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1280
1300
|
|
|
1281
|
-
|
|
1301
|
+
const looksLikeObject = value => lodash.isPlainObject(value);
|
|
1282
1302
|
|
|
1283
|
-
|
|
1284
|
-
|
|
1303
|
+
const getExpectedObjectDiff = (actual, expected) => Object.fromEntries(getKeys(expected).map(key => {
|
|
1304
|
+
const expectedValue = getKey(expected, key);
|
|
1305
|
+
const actualValue = getKey(actual, key);
|
|
1306
|
+
|
|
1307
|
+
if (isMatcher(expectedValue)) {
|
|
1308
|
+
return [key, expectedValue.getDiff(actualValue).expected];
|
|
1285
1309
|
}
|
|
1286
1310
|
|
|
1287
|
-
if (looksLikeObject(
|
|
1288
|
-
return [key, getExpectedObjectDiff(
|
|
1311
|
+
if (looksLikeObject(expectedValue)) {
|
|
1312
|
+
return [key, getExpectedObjectDiff(actualValue, expectedValue)];
|
|
1289
1313
|
}
|
|
1290
1314
|
|
|
1291
|
-
return [key,
|
|
1315
|
+
return [key, expectedValue];
|
|
1292
1316
|
}));
|
|
1293
1317
|
|
|
1294
1318
|
const getActualObjectDiff = (actual, expected) => {
|
|
1295
|
-
|
|
1319
|
+
const actualKeys = getKeys(actual);
|
|
1320
|
+
const expectedKeys = new Set(getKeys(expected));
|
|
1321
|
+
const commonKeys = actualKeys.filter(key => expectedKeys.has(key));
|
|
1322
|
+
|
|
1323
|
+
if (!commonKeys.length) {
|
|
1324
|
+
// When we don't have any common keys we return the whole object
|
|
1325
|
+
// so the user can inspect what's in there.
|
|
1296
1326
|
return actual;
|
|
1297
1327
|
}
|
|
1298
1328
|
|
|
1299
|
-
return Object.fromEntries(
|
|
1300
|
-
const
|
|
1301
|
-
const
|
|
1302
|
-
|
|
1303
|
-
if (!left) {
|
|
1304
|
-
return [];
|
|
1305
|
-
}
|
|
1329
|
+
return Object.fromEntries(commonKeys.map(key => {
|
|
1330
|
+
const expectedValue = getKey(expected, key);
|
|
1331
|
+
const actualValue = getKey(actual, key);
|
|
1306
1332
|
|
|
1307
|
-
if (isMatcher(
|
|
1308
|
-
return [key,
|
|
1333
|
+
if (isMatcher(expectedValue)) {
|
|
1334
|
+
return [key, expectedValue.getDiff(actualValue).actual];
|
|
1309
1335
|
}
|
|
1310
1336
|
|
|
1311
|
-
if (looksLikeObject(
|
|
1312
|
-
return [key, getActualObjectDiff(
|
|
1337
|
+
if (looksLikeObject(expectedValue)) {
|
|
1338
|
+
return [key, getActualObjectDiff(actualValue, expectedValue)];
|
|
1313
1339
|
}
|
|
1314
1340
|
|
|
1315
|
-
return [key,
|
|
1341
|
+
return [key, actualValue];
|
|
1316
1342
|
}));
|
|
1317
1343
|
};
|
|
1318
1344
|
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1321
|
-
|
|
1345
|
+
const getKeys = value => {
|
|
1346
|
+
if (typeof value === 'object' && value !== null) {
|
|
1347
|
+
return Reflect.ownKeys(value);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
return [];
|
|
1351
|
+
};
|
|
1322
1352
|
|
|
1323
|
-
|
|
1353
|
+
const getKey = (value, key) => // @ts-expect-error because we're fine with a runtime undefined value
|
|
1354
|
+
value == null ? void 0 : value[key];
|
|
1355
|
+
|
|
1356
|
+
const isMatch = (actual, expected) => {
|
|
1357
|
+
const actualKeys = getKeys(actual);
|
|
1358
|
+
const expectedKeys = getKeys(expected);
|
|
1359
|
+
|
|
1360
|
+
if (!isArray(expectedKeys).matches(actualKeys)) {
|
|
1324
1361
|
return false;
|
|
1325
1362
|
}
|
|
1326
1363
|
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1364
|
+
return expectedKeys.every(key => {
|
|
1365
|
+
const expectedValue = getKey(expected, key);
|
|
1366
|
+
const actualValue = getKey(actual, key);
|
|
1330
1367
|
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1368
|
+
if (isMatcher(expectedValue)) {
|
|
1369
|
+
return expectedValue.matches(actualValue);
|
|
1370
|
+
}
|
|
1334
1371
|
|
|
1335
|
-
|
|
1336
|
-
|
|
1372
|
+
if (looksLikeObject(expectedValue)) {
|
|
1373
|
+
return isMatch(actualValue, expectedValue);
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
return deepEquals(expectedValue).matches(actualValue);
|
|
1377
|
+
});
|
|
1378
|
+
};
|
|
1337
1379
|
|
|
1338
1380
|
const deepPrintObject = value => lodash.cloneDeepWith(value, value => {
|
|
1339
1381
|
if (isMatcher(value)) {
|
|
@@ -1343,57 +1385,35 @@ const deepPrintObject = value => lodash.cloneDeepWith(value, value => {
|
|
|
1343
1385
|
return undefined;
|
|
1344
1386
|
});
|
|
1345
1387
|
/**
|
|
1346
|
-
*
|
|
1388
|
+
* Check if an object recursively contains the expected properties,
|
|
1389
|
+
* i.e. the expected object is a subset of the received object.
|
|
1347
1390
|
*
|
|
1348
|
-
*
|
|
1349
|
-
*
|
|
1350
|
-
*
|
|
1351
|
-
*
|
|
1352
|
-
*
|
|
1391
|
+
* @param partial A subset of the expected object that will be recursively matched.
|
|
1392
|
+
* Supports nested matchers.
|
|
1393
|
+
* Concrete values will be compared with {@link deepEquals}.
|
|
1394
|
+
* Note that a `{}` partial will match ANY value including non-objects.
|
|
1395
|
+
* Use {@link isPlainObject} if you want to match any plain object.
|
|
1353
1396
|
*
|
|
1354
1397
|
* @example
|
|
1355
1398
|
* const fn = mock<(pos: { x: number, y: number }) => number>();
|
|
1356
|
-
* when(() => fn(It.
|
|
1399
|
+
* when(() => fn(It.isPartial({ x: 23 }))).returns(42);
|
|
1357
1400
|
*
|
|
1358
|
-
* fn({ x: 100, y: 200 }) // throws
|
|
1359
1401
|
* fn({ x: 23, y: 200 }) // returns 42
|
|
1360
1402
|
*
|
|
1361
1403
|
* @example
|
|
1362
|
-
* It.
|
|
1404
|
+
* It.isPartial({ foo: It.isString() })
|
|
1363
1405
|
*/
|
|
1406
|
+
// T is not constrained to ObjectType because of
|
|
1407
|
+
// https://github.com/microsoft/TypeScript/issues/57810,
|
|
1408
|
+
// but K is to avoid inferring non-object partials
|
|
1364
1409
|
|
|
1365
1410
|
|
|
1366
|
-
const
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
return true;
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
return isMatch(actual, partial);
|
|
1376
|
-
}, {
|
|
1377
|
-
toString: () => {
|
|
1378
|
-
if (!partial) {
|
|
1379
|
-
return 'Matcher<object>';
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
return `Matcher<object>(${printValue(deepPrintObject(partial))})`;
|
|
1383
|
-
},
|
|
1384
|
-
getDiff: actual => {
|
|
1385
|
-
if (!partial) {
|
|
1386
|
-
return {
|
|
1387
|
-
expected: 'Matcher<object>',
|
|
1388
|
-
actual: `${printValue(actual)}`
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
return {
|
|
1393
|
-
actual: getActualObjectDiff(actual, partial),
|
|
1394
|
-
expected: getExpectedObjectDiff(actual, partial)
|
|
1395
|
-
};
|
|
1396
|
-
}
|
|
1411
|
+
const isPartial = partial => matches(actual => isMatch(actual, partial), {
|
|
1412
|
+
toString: () => `Matcher<object>(${printValue(deepPrintObject(partial))})`,
|
|
1413
|
+
getDiff: actual => ({
|
|
1414
|
+
actual: getActualObjectDiff(actual, partial),
|
|
1415
|
+
expected: getExpectedObjectDiff(actual, partial)
|
|
1416
|
+
})
|
|
1397
1417
|
});
|
|
1398
1418
|
|
|
1399
1419
|
/**
|
|
@@ -1496,7 +1516,8 @@ var it = {
|
|
|
1496
1516
|
isAny: isAny,
|
|
1497
1517
|
isArray: isArray,
|
|
1498
1518
|
isNumber: isNumber,
|
|
1499
|
-
|
|
1519
|
+
isPlainObject: isPlainObject,
|
|
1520
|
+
isPartial: isPartial,
|
|
1500
1521
|
isString: isString,
|
|
1501
1522
|
matches: matches,
|
|
1502
1523
|
willCapture: willCapture
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/expectation/expectation.ts","../src/matchers/matcher.ts","../src/print.ts","../src/errors/unexpected-access.ts","../src/errors/unexpected-call.ts","../src/mock/options.ts","../src/expectation/repository/return-value.ts","../src/expectation/repository/flexible-repository.ts","../src/expectation/strong-expectation.ts","../src/errors/api.ts","../src/when/expectation-builder.ts","../src/matchers/deep-equals.ts","../src/mock/defaults.ts","../src/mock/map.ts","../src/proxy.ts","../src/mock/stub.ts","../src/mock/mock.ts","../src/return/invocation-count.ts","../src/return/returns.ts","../src/when/when.ts","../src/verify/reset.ts","../src/errors/verify.ts","../src/verify/verify.ts","../src/matchers/is.ts","../src/matchers/is-any.ts","../src/matchers/is-array.ts","../src/matchers/is-number.ts","../src/matchers/is-object.ts","../src/matchers/is-string.ts","../src/matchers/will-capture.ts","../src/matchers/it.ts"],"sourcesContent":["import type { Matcher } from '../matchers/matcher';\nimport type { Property } from '../proxy';\nimport type { ReturnValue } from './repository/return-value';\n\n/**\n * Compare received arguments against matchers.\n */\nexport interface Expectation {\n property: Property;\n\n /**\n * `undefined` means this is a property expectation.\n * `[]` means this is a function call with no arguments.\n */\n args: Matcher[] | undefined;\n\n returnValue: ReturnValue;\n\n min: number;\n\n max: number;\n\n /**\n * How many times should this expectation match?\n */\n setInvocationCount: (min: number, max: number) => void;\n\n matches: (args: unknown[] | undefined) => boolean;\n\n toString: () => string;\n}\n\n/**\n * Special symbol denoting the call of a function.\n */\nexport const ApplyProp = Symbol('apply');\n","export const MATCHER_SYMBOL = Symbol('matcher');\n\nexport type MatcherOptions = {\n /**\n * Will be called when printing the diff between an expectation and the\n * (mismatching) received arguments.\n *\n * With this function you can pretty print the `actual` and `expected` values\n * according to your matcher's logic.\n *\n * @param actual The actual value received by this matcher, same as the one\n * in `matches`.\n *\n * @example\n * const neverMatcher = It.matches(() => false, {\n * getDiff: (actual) => ({ actual, expected: 'never' })\n * });\n *\n * when(() => fn(neverMatcher)).thenReturn(42);\n *\n * fn(42);\n * // - Expected\n * // + Received\n * //\n * // - 'never'\n * // + 42\n */\n getDiff: (actual: any) => { actual: any; expected: any };\n\n /**\n * Will be called when printing arguments for an unexpected or unmet expectation.\n *\n * @example\n * const neverMatcher = It.matches(() => false, {\n * toString: () => 'never'\n * });\n * when(() => fn(neverMatcher)).thenReturn(42);\n *\n * fn(42);\n * // Unmet expectations:\n * // when(() => fn(never)).thenReturn(42)\n */\n toString: () => string;\n};\n\n/**\n * You MUST use {@link It.matches} to create this branded type.\n */\nexport interface Matcher extends MatcherOptions {\n [MATCHER_SYMBOL]: boolean;\n\n /**\n * Will be called with the received value and should return whether it matches\n * the expectation.\n */\n matches: (actual: any) => boolean;\n}\n\n/**\n * This takes the shape of T to satisfy call sites, but strong-mock will only\n * care about the matcher type.\n */\nexport type TypeMatcher<T> = T & Matcher;\n\n/**\n * Used to test if an expectation is an argument is a custom matcher.\n */\nexport function isMatcher(f: unknown): f is Matcher {\n return !!(f && (<Matcher>f)[MATCHER_SYMBOL]);\n}\n\nexport const getMatcherDiffs = (\n matchers: Matcher[],\n args: unknown[]\n): { actual: unknown[]; expected: unknown[] } => {\n const matcherDiffs = matchers.map((matcher, i) => matcher.getDiff(args[i]));\n const actual = matcherDiffs.map((d) => d.actual);\n const expected = matcherDiffs.map((d) => d.expected);\n\n return { actual, expected };\n};\n\n/**\n * Create a custom matcher.\n *\n * @param predicate Will receive the actual value and return whether it matches the expectation.\n * @param options\n * @param options.toString An optional function that should return a string that will be\n * used when the matcher needs to be printed in an error message. By default,\n * it stringifies `predicate`.\n * @param options.getDiff An optional function that will be called when printing the\n * diff for a failed expectation. It will only be called if there's a mismatch\n * between the expected and received values i.e. `predicate(actual)` fails.\n * By default, the `toString` method will be used to format the expected value,\n * while the received value will be returned as-is.\n *\n * @example\n * // Create a matcher for positive numbers.\n * const fn = mock<(x: number) => number>();\n * when(() => fn(It.matches(x => x >= 0))).thenReturn(42);\n *\n * fn(2) === 42\n * fn(-1) // throws\n */\nexport const matches = <T>(\n predicate: (actual: T) => boolean,\n options?: Partial<MatcherOptions>\n): TypeMatcher<T> => {\n // We can't use destructuring with default values because `options` is optional,\n // so it needs a default value of `{}`, which will come with a native `toString`.\n const toString =\n options?.toString ?? (() => `Matcher(${predicate.toString()})`);\n const getDiff =\n options?.getDiff ??\n ((actual) => ({\n actual,\n expected: toString(),\n }));\n\n const matcher: Matcher = {\n [MATCHER_SYMBOL]: true,\n matches: (actual: T) => predicate(actual),\n toString,\n getDiff: (actual) => {\n if (predicate(actual)) {\n return {\n actual,\n expected: actual,\n };\n }\n\n return getDiff(actual);\n },\n };\n\n return matcher as any;\n};\n","import { EXPECTED_COLOR, RECEIVED_COLOR, stringify } from 'jest-matcher-utils';\nimport type { Expectation } from './expectation/expectation';\nimport { ApplyProp } from './expectation/expectation';\nimport type { ReturnValue } from './expectation/repository/return-value';\nimport { isMatcher } from './matchers/matcher';\nimport type { Property } from './proxy';\n\nexport const printProperty = (property: Property) => {\n if (property === ApplyProp) {\n return '';\n }\n\n if (typeof property === 'symbol') {\n return `[${property.toString()}]`;\n }\n\n return `.${property}`;\n};\n\nexport const printValue = (arg: unknown): string => {\n // Call toString on matchers directly to avoid wrapping strings returned by them in quotes.\n if (isMatcher(arg)) {\n return arg.toString();\n }\n\n return stringify(arg);\n};\n\nconst printArgs = (args: any[]) =>\n args.map((arg) => printValue(arg)).join(', ');\n\nexport const printCall = (property: Property, args?: any[]) => {\n const prettyProperty = printProperty(property);\n\n if (args) {\n const prettyArgs = printArgs(args);\n\n return `mock${RECEIVED_COLOR(`${prettyProperty}(${prettyArgs})`)}`;\n }\n\n return `mock${RECEIVED_COLOR(`${prettyProperty}`)}`;\n};\n\nexport const printReturns = (\n { isError, isPromise, value }: ReturnValue,\n min: number,\n max: number\n) => {\n let thenPrefix = '';\n\n if (isPromise) {\n if (isError) {\n thenPrefix += 'thenReject';\n } else {\n thenPrefix += 'thenResolve';\n }\n } else if (isError) {\n thenPrefix += 'thenThrow';\n } else {\n thenPrefix += 'thenReturn';\n }\n\n return `.${thenPrefix}(${RECEIVED_COLOR(\n printValue(value)\n )}).between(${min}, ${max})`;\n};\n\nexport const printWhen = (property: Property, args: any[] | undefined) => {\n const prettyProperty = printProperty(property);\n\n if (args) {\n return `when(() => mock${EXPECTED_COLOR(\n `${prettyProperty}(${printArgs(args)})`\n )})`;\n }\n\n return `when(() => mock${EXPECTED_COLOR(`${printProperty(property)}`)})`;\n};\n\nexport const printExpectation = (\n property: Property,\n args: any[] | undefined,\n returnValue: ReturnValue,\n min: number,\n max: number\n) => `${printWhen(property, args)}${printReturns(returnValue, min, max)}`;\n\nexport const printRemainingExpectations = (expectations: Expectation[]) =>\n expectations.length\n ? `Remaining unmet expectations:\n - ${expectations.map((e) => e.toString()).join('\\n - ')}`\n : 'There are no remaining unmet expectations.';\n","import { DIM_COLOR } from 'jest-matcher-utils';\nimport type { Expectation } from '../expectation/expectation';\nimport { printCall, printRemainingExpectations } from '../print';\nimport type { Property } from '../proxy';\n\nexport class UnexpectedAccess extends Error {\n constructor(property: Property, expectations: Expectation[]) {\n super(\n DIM_COLOR(`Didn't expect ${printCall(property)} to be accessed.\n\nIf you expect this property to be accessed then please\nset an expectation for it.\n\n${printRemainingExpectations(expectations)}`)\n );\n }\n}\n","import { diff as printDiff } from 'jest-diff';\nimport { DIM_COLOR, EXPECTED_COLOR, RECEIVED_COLOR } from 'jest-matcher-utils';\nimport stripAnsi from 'strip-ansi';\nimport type { Expectation } from '../expectation/expectation';\nimport { getMatcherDiffs } from '../matchers/matcher';\nimport { printCall } from '../print';\nimport type { Property } from '../proxy';\n\ntype MatcherResult = {\n expected: unknown;\n actual: unknown;\n};\n\n// This is taken from jest.\ninterface MatcherError {\n matcherResult?: MatcherResult;\n}\n\nexport const printArgsDiff = (\n expected: unknown[],\n actual: unknown[]\n): string => {\n const diff = printDiff(expected, actual, { omitAnnotationLines: true });\n\n /* istanbul ignore next this is not expected in practice */\n if (!diff) {\n return '';\n }\n\n const ansilessDiffLines = stripAnsi(diff).split('\\n');\n let relevantDiffLines: string[];\n\n // Strip Array [ ... ] surroundings.\n if (!expected.length) {\n // - Array []\n // + Array [\n // ...\n // ]\n relevantDiffLines = ansilessDiffLines.slice(2, -1);\n } else if (!actual.length) {\n // - Array [\n // ...\n // ]\n // + Array []\n relevantDiffLines = ansilessDiffLines.slice(1, -2);\n } else {\n // Array [\n // ...\n // ]\n relevantDiffLines = ansilessDiffLines.slice(1, -1);\n }\n\n // Strip the trailing comma.\n const lastLine = relevantDiffLines[relevantDiffLines.length - 1].slice(0, -1);\n\n const coloredDiffLines = [...relevantDiffLines.slice(0, -1), lastLine].map(\n (line) => {\n const first = line.charAt(0);\n\n switch (first) {\n case '-':\n return EXPECTED_COLOR(line);\n case '+':\n return RECEIVED_COLOR(line);\n default:\n return line;\n }\n }\n );\n\n return coloredDiffLines.join('\\n');\n};\n\nexport const printExpectationDiff = (e: Expectation, args: unknown[]) => {\n if (!e.args?.length) {\n return '';\n }\n\n const { actual, expected } = getMatcherDiffs(e.args, args);\n\n return printArgsDiff(expected, actual);\n};\n\nexport const printDiffForAllExpectations = (\n expectations: Expectation[],\n actual: unknown[]\n) =>\n expectations\n .map((e) => {\n const diff = printExpectationDiff(e, actual);\n\n if (diff) {\n return `${e.toString()}\n${EXPECTED_COLOR('- Expected')}\n${RECEIVED_COLOR('+ Received')}\n\n${diff}`;\n }\n\n return undefined;\n })\n .filter((x) => x)\n .join('\\n\\n');\n\nexport class UnexpectedCall extends Error implements MatcherError {\n public matcherResult?: MatcherResult;\n\n constructor(\n property: Property,\n args: unknown[],\n expectations: Expectation[]\n ) {\n const header = `Didn't expect ${printCall(property, args)} to be called.`;\n\n const propertyExpectations = expectations.filter(\n (e) => e.property === property\n );\n\n if (propertyExpectations.length) {\n super(\n DIM_COLOR(`${header}\n\nRemaining expectations:\n${printDiffForAllExpectations(propertyExpectations, args)}`)\n );\n\n // If we have a single expectation we can attach the actual/expected args\n // to the error instance, so that an IDE may show its own diff for them.\n if (\n propertyExpectations.length === 1 &&\n propertyExpectations[0].args?.length\n ) {\n const { actual, expected } = getMatcherDiffs(\n propertyExpectations[0].args,\n args\n );\n this.matcherResult = {\n actual,\n expected,\n };\n }\n } else {\n super(\n DIM_COLOR(`${header}\n \nNo remaining expectations.`)\n );\n }\n }\n}\n","import type { Matcher } from '../matchers/matcher';\n\nexport type ConcreteMatcher = <T>(expected: T) => Matcher;\n\nexport enum UnexpectedProperty {\n /**\n * Throw an error immediately.\n *\n * @example\n * // Will throw \"Didn't expect foo to be accessed\".\n * const { foo } = service;\n *\n * // Will throw \"Didn't expect foo to be accessed\",\n * // without printing the arguments.\n * foo(42);\n */\n THROW,\n\n /**\n * Return a function that will throw if called. This can be useful if your\n * code destructures a function but never calls it.\n *\n * It will also improve error messages for unexpected calls because arguments\n * will be captured instead of throwing immediately on the property access.\n *\n * The function will be returned even if the property is not supposed to be a\n * function. This could cause weird behavior at runtime, when your code expects\n * e.g. a number and gets a function instead.\n *\n * @example\n * // This will NOT throw.\n * const { foo } = service;\n *\n * // This will NOT throw, and might produce unexpected results.\n * foo > 0\n *\n * // Will throw \"Didn't expect foo(42) to be called\".\n * foo(42);\n */\n CALL_THROW,\n}\n\nexport interface MockOptions {\n /**\n * Controls what should be returned for a property with no expectations.\n *\n * A property with no expectations is a property that has no `when`\n * expectations set on it. It can also be a property that ran out of `when`\n * expectations.\n *\n * The default is to return a function that will throw when called.\n *\n * @example\n * const foo = mock<{ bar: () => number }>();\n * foo.bar() // unexpected property access\n *\n * @example\n * const foo = mock<{ bar: () => number }>();\n * when(() => foo.bar()).thenReturn(42);\n * foo.bar() === 42\n * foo.bar() // unexpected property access\n */\n unexpectedProperty?: UnexpectedProperty;\n\n /**\n * If `true`, the number of received arguments in a function/method call has to\n * match the number of arguments set in the expectation.\n *\n * If `false`, extra parameters are considered optional and checked by the\n * TypeScript compiler instead.\n *\n * You may want to set this to `true` if you're not using TypeScript,\n * or if you want to be extra strict.\n *\n * @example\n * const fn = mock<(value?: number) => number>({ exactParams: true });\n * when(() => fn()).thenReturn(42);\n *\n * fn(100) // throws with exactParams, returns 42 without\n */\n exactParams?: boolean;\n\n /**\n * The matcher that will be used when one isn't specified explicitly.\n *\n * The most common use case is replacing the default {@link It.deepEquals}\n * matcher with {@link It.is}, but you can also use {@link It.matches} to\n * create a custom matcher.\n *\n * @param expected The concrete expected value received from the\n * {@link when} expectation.\n *\n * @example\n * const fn = mock<(value: number[]) => boolean>({\n * concreteMatcher: It.is\n * });\n *\n * const expected = [1, 2, 3];\n * when(() => fn(expected).thenReturn(true);\n *\n * fn([1, 2, 3]); // throws because different array instance\n * fn(expected); // OK\n */\n concreteMatcher?: ConcreteMatcher;\n}\n","export type ReturnValue = {\n value: any;\n isPromise?: boolean;\n isError?: boolean;\n};\n\n/**\n * Unbox the expectation's return value.\n *\n * If the value is an error then throw it.\n *\n * If the value is a promise then resolve/reject it.\n */\nexport const unboxReturnValue = ({\n isError,\n isPromise,\n value,\n}: ReturnValue) => {\n if (isError) {\n if (value instanceof Error) {\n if (isPromise) {\n return Promise.reject(value);\n }\n throw value;\n }\n\n if (isPromise) {\n return Promise.reject(new Error(value));\n }\n\n throw new Error(value);\n }\n\n if (isPromise) {\n return Promise.resolve(value);\n }\n\n return value;\n};\n","import { UnexpectedAccess } from '../../errors/unexpected-access';\nimport { UnexpectedCall } from '../../errors/unexpected-call';\nimport { MATCHER_SYMBOL } from '../../matchers/matcher';\nimport { UnexpectedProperty } from '../../mock/options';\nimport type { Property } from '../../proxy';\nimport type { Expectation } from '../expectation';\nimport { ApplyProp } from '../expectation';\nimport type { CallMap, ExpectationRepository } from './expectation-repository';\nimport { unboxReturnValue } from './return-value';\n\ntype CountableExpectation = {\n expectation: Expectation;\n matchCount: number;\n};\n\n/**\n * An expectation repository with a configurable behavior for\n * unexpected property access.\n */\nexport class FlexibleRepository implements ExpectationRepository {\n constructor(\n private unexpectedProperty: UnexpectedProperty = UnexpectedProperty.THROW\n ) {}\n\n protected readonly expectations = new Map<Property, CountableExpectation[]>();\n\n private readonly expectedCallStats: CallMap = new Map();\n\n private readonly unexpectedCallStats: CallMap = new Map();\n\n add(expectation: Expectation): void {\n const { property } = expectation;\n\n const expectations = this.expectations.get(property) || [];\n\n this.expectations.set(property, [\n ...expectations,\n {\n expectation,\n matchCount: 0,\n },\n ]);\n }\n\n clear(): void {\n this.expectations.clear();\n this.expectedCallStats.clear();\n this.unexpectedCallStats.clear();\n }\n\n apply = (args: unknown[]): unknown => this.get(ApplyProp)(...args);\n\n // TODO: this returns any, but the interface returns unknown\n // unknown causes errors in apply tests, and any causes bugs in bootstrapped SM\n get(property: Property): any {\n const expectations = this.expectations.get(property);\n\n if (expectations && expectations.length) {\n return this.handlePropertyWithMatchingExpectations(\n property,\n expectations\n );\n }\n\n return this.handlePropertyWithNoExpectations(property);\n }\n\n private handlePropertyWithMatchingExpectations = (\n property: Property,\n expectations: CountableExpectation[]\n ) => {\n // Avoid recording call stats for function calls, since the property is an\n // internal detail.\n if (property !== ApplyProp) {\n // An unexpected call could still happen later, if the property returns a\n // function that will not match the given args.\n this.recordExpected(property, undefined);\n }\n\n const propertyExpectation = expectations.find((e) =>\n e.expectation.matches(undefined)\n );\n\n if (propertyExpectation) {\n this.countAndConsume(propertyExpectation);\n\n return unboxReturnValue(propertyExpectation.expectation.returnValue);\n }\n\n return (...args: any[]) => {\n const callExpectation = expectations.find((e) =>\n e.expectation.matches(args)\n );\n\n if (callExpectation) {\n this.recordExpected(property, args);\n this.countAndConsume(callExpectation);\n\n return unboxReturnValue(callExpectation.expectation.returnValue);\n }\n\n return this.getValueForUnexpectedCall(property, args);\n };\n };\n\n private handlePropertyWithNoExpectations = (property: Property) => {\n switch (property) {\n case 'toString':\n return () => 'mock';\n case '@@toStringTag':\n case Symbol.toStringTag:\n case 'name':\n return 'mock';\n\n // Promise.resolve() tries to see if it's a \"thenable\".\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables\n case 'then':\n return undefined;\n\n // pretty-format\n case '$$typeof':\n case 'constructor':\n case '@@__IMMUTABLE_ITERABLE__@@':\n case '@@__IMMUTABLE_RECORD__@@':\n return null;\n\n case MATCHER_SYMBOL:\n return false;\n\n case ApplyProp:\n return (...args: any[]) =>\n this.getValueForUnexpectedCall(property, args);\n default:\n return this.getValueForUnexpectedAccess(property);\n }\n };\n\n getAllProperties(): Property[] {\n return Array.from(this.expectations.keys());\n }\n\n getCallStats() {\n return {\n expected: this.expectedCallStats,\n unexpected: this.unexpectedCallStats,\n };\n }\n\n getUnmet(): Expectation[] {\n return ([] as Expectation[]).concat(\n ...Array.from(this.expectations.values()).map((expectations) =>\n expectations\n .filter((e) => e.expectation.min > e.matchCount)\n .map((e) => e.expectation)\n )\n );\n }\n\n private recordExpected(property: Property, args: any[] | undefined) {\n const calls = this.expectedCallStats.get(property) || [];\n\n this.expectedCallStats.set(property, [...calls, { arguments: args }]);\n }\n\n private recordUnexpected(property: Property, args: any[] | undefined) {\n const calls = this.unexpectedCallStats.get(property) || [];\n\n this.unexpectedCallStats.set(property, [...calls, { arguments: args }]);\n }\n\n private countAndConsume(expectation: CountableExpectation) {\n // eslint-disable-next-line no-param-reassign\n expectation.matchCount++;\n\n this.consumeExpectation(expectation);\n }\n\n private consumeExpectation(expectation: CountableExpectation): void {\n const { property, max } = expectation.expectation;\n\n const expectations = this.expectations.get(property)!;\n\n if (expectation.matchCount === max) {\n this.expectations.set(\n property,\n expectations.filter((e) => e !== expectation)\n );\n }\n }\n\n private getValueForUnexpectedCall(property: Property, args: any[]): never {\n this.recordUnexpected(property, args);\n\n throw new UnexpectedCall(property, args, this.getUnmet());\n }\n\n private getValueForUnexpectedAccess(property: Property): unknown {\n if (this.unexpectedProperty === UnexpectedProperty.THROW) {\n this.recordUnexpected(property, undefined);\n\n throw new UnexpectedAccess(property, this.getUnmet());\n }\n\n return (...args: unknown[]) => {\n this.recordUnexpected(property, args);\n\n throw new UnexpectedCall(property, args, this.getUnmet());\n };\n }\n}\n","import type { Matcher } from '../matchers/matcher';\nimport { printExpectation } from '../print';\nimport type { Property } from '../proxy';\nimport type { Expectation } from './expectation';\nimport type { ReturnValue } from './repository/return-value';\n\n/**\n * Matches a call with more parameters than expected because it is assumed the\n * compiler will check that those parameters are optional.\n *\n * @example\n * new StrongExpectation(\n * 'bar',\n * deepEquals([1, 2, 3]),\n * 23\n * ).matches('bar', [1, 2, 3]) === true;\n */\nexport class StrongExpectation implements Expectation {\n private matched = 0;\n\n public min = 1;\n\n public max = 1;\n\n constructor(\n public property: Property,\n public args: Matcher[] | undefined,\n public returnValue: ReturnValue,\n private exactParams: boolean = false\n ) {}\n\n setInvocationCount(min: number, max = 1) {\n this.min = min;\n this.max = max;\n }\n\n matches(args: any[] | undefined): boolean {\n if (!this.matchesArgs(args)) {\n return false;\n }\n\n this.matched++;\n\n return this.max === 0 || this.matched <= this.max;\n }\n\n isUnmet(): boolean {\n return this.matched < this.min;\n }\n\n private matchesArgs(received: any[] | undefined) {\n if (this.args === undefined) {\n return !received;\n }\n\n if (!received) {\n return false;\n }\n\n if (this.exactParams) {\n if (this.args.length !== received.length) {\n return false;\n }\n }\n\n return this.args.every((arg, i) => arg.matches(received[i]));\n }\n\n toString() {\n return printExpectation(\n this.property,\n this.args,\n this.returnValue,\n this.min,\n this.max\n );\n }\n}\n","import { printProperty, printWhen } from '../print';\nimport type { Property } from '../proxy';\n\nexport class UnfinishedExpectation extends Error {\n constructor(property: Property, args: any[] | undefined) {\n super(`There is an unfinished pending expectation:\n\n${printWhen(property, args)}\n\nPlease finish it by setting a return value even if the value\nis undefined.`);\n }\n}\n\nexport class MissingWhen extends Error {\n constructor() {\n super(`You tried setting a return value without an expectation.\n\nEvery call to set a return value must be preceded by an expectation.`);\n }\n}\n\nexport class NotAMock extends Error {\n constructor() {\n super(`We couldn't find the mock.\n\nMake sure you're passing in an actual mock.`);\n }\n}\n\nexport class NestedWhen extends Error {\n constructor(parentProp: Property, childProp: Property) {\n const snippet = `\nconst parentMock = mock<T1>();\nconst childMock = mock<T2>();\n\nwhen(() => childMock${printProperty(childProp)}).thenReturn(...);\nwhen(() => parentMock${printProperty(parentProp)}).thenReturn(childMock)\n`;\n\n super(\n `Setting an expectation on a nested property is not supported.\n\nYou can return an object directly when the first property is accessed,\nor you can even return a separate mock:\n${snippet}`\n );\n }\n}\n","import { MissingWhen, UnfinishedExpectation } from '../errors/api';\nimport type { Expectation } from '../expectation/expectation';\nimport type { ReturnValue } from '../expectation/repository/return-value';\nimport type { ConcreteMatcher } from '../mock/options';\nimport type { Property } from '../proxy';\n\n/**\n * An expectation has to be built incrementally, starting first with the property\n * being accessed inside {@link createStub}, then any arguments passed to it, and ending\n * it with the returned value from {@link createReturns}.\n */\nexport interface ExpectationBuilder {\n setProperty: (prop: Property) => void;\n\n setArgs: (args: unknown[] | undefined) => void;\n\n finish: (returnValue: ReturnValue) => Expectation;\n}\n\nexport type ExpectationFactory = (\n property: Property,\n args: any[] | undefined,\n returnValue: ReturnValue,\n concreteMatcher: ConcreteMatcher,\n exactParams: boolean\n) => Expectation;\n\nexport class ExpectationBuilderWithFactory implements ExpectationBuilder {\n private args: unknown[] | undefined;\n\n private property: Property | undefined;\n\n constructor(\n private createExpectation: ExpectationFactory,\n private concreteMatcher: ConcreteMatcher,\n private exactParams: boolean\n ) {}\n\n setProperty(value: Property) {\n if (this.property) {\n throw new UnfinishedExpectation(this.property, this.args);\n }\n\n this.property = value;\n }\n\n setArgs(value: unknown[] | undefined) {\n this.args = value;\n }\n\n finish(returnValue: ReturnValue): Expectation {\n if (!this.property) {\n throw new MissingWhen();\n }\n\n const expectation = this.createExpectation(\n this.property,\n this.args,\n returnValue,\n this.concreteMatcher,\n this.exactParams\n );\n\n this.property = undefined;\n this.args = undefined;\n\n return expectation;\n }\n}\n","import { isEqual, isObjectLike, isUndefined, omitBy } from 'lodash';\nimport { printValue } from '../print';\nimport type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\nconst removeUndefined = (object: any): any => {\n if (Array.isArray(object)) {\n return object.map((x) => removeUndefined(x));\n }\n\n if (!isObjectLike(object)) {\n return object;\n }\n\n return omitBy(object, isUndefined);\n};\n\n/**\n * Compare values using deep equality.\n *\n * @param expected\n * @param strict By default, this matcher will treat a missing key in an object\n * and a key with the value `undefined` as not equal. It will also consider\n * non `Object` instances with different constructors as not equal. Setting\n * this to `false` will consider the objects in both cases as equal.\n *\n * @see {@link It.isObject} or {@link It.isArray} if you want to nest matchers.\n * @see {@link It.is} if you want to use strict equality.\n */\nexport const deepEquals = <T>(\n expected: T,\n {\n strict = true,\n }: {\n strict?: boolean;\n } = {}\n): TypeMatcher<T> =>\n matches(\n (actual) => {\n if (strict) {\n return isEqual(actual, expected);\n }\n\n return isEqual(removeUndefined(actual), removeUndefined(expected));\n },\n {\n toString: () => printValue(expected),\n getDiff: (actual) => ({\n actual,\n expected,\n }),\n }\n );\n","import { deepEquals } from '../matchers/deep-equals';\nimport type { MockOptions } from './options';\nimport { UnexpectedProperty } from './options';\n\nexport type StrongMockDefaults = Required<MockOptions>;\n\nconst defaults: StrongMockDefaults = {\n concreteMatcher: deepEquals,\n unexpectedProperty: UnexpectedProperty.CALL_THROW,\n exactParams: false,\n};\n\nexport let currentDefaults: StrongMockDefaults = defaults;\n\n/**\n * Override strong-mock's defaults.\n *\n * @param newDefaults These will be applied to the library defaults. Multiple\n * calls don't stack e.g. calling this with `{}` will clear any previously\n * applied defaults.\n */\nexport const setDefaults = (newDefaults: MockOptions): void => {\n currentDefaults = {\n ...defaults,\n ...newDefaults,\n };\n};\n","import { NotAMock } from '../errors/api';\nimport type { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport type { ExpectationBuilder } from '../when/expectation-builder';\nimport type { StrongMockDefaults } from './defaults';\nimport type { Mock } from './mock';\n\n/**\n * Since `when` doesn't receive the mock subject (because we can't make it\n * consistently return it from `mock()`, `mock.foo` and `mock.bar()`) we need\n * to store a global state for the currently active mock.\n *\n * We also want to throw in the following case:\n *\n * ```\n * when(() => mock()) // forgot returns here\n * when(() => mock()) // should throw\n * ```\n *\n * For that reason we can't just store the currently active mock, but also\n * whether we finished the expectation or not.\n */\nlet activeMock: Mock<any> | undefined;\n\nexport const setActiveMock = (mock: Mock<any>) => {\n activeMock = mock;\n};\n\nexport const clearActiveMock = () => {\n activeMock = undefined;\n};\n\nexport const getActiveMock = (): Mock<any> => activeMock;\n\ntype MockState = {\n repository: ExpectationRepository;\n builder: ExpectationBuilder;\n options: StrongMockDefaults;\n};\n\n/**\n * Store a global map of all mocks created and their state.\n *\n * This is needed because we can't reliably pass the state between `when`\n * and `thenReturn`.\n */\nconst mockMap = new Map<Mock<any>, MockState>();\n\nexport const getMockState = (mock: Mock<any>): MockState => {\n if (mockMap.has(mock)) {\n return mockMap.get(mock)!;\n }\n\n throw new NotAMock();\n};\n\nexport const setMockState = (mock: Mock<any>, state: MockState): void => {\n mockMap.set(mock, state);\n};\n\nexport const getAllMocks = (): [Mock<any>, MockState][] =>\n Array.from(mockMap.entries());\n","import type { Mock } from './mock/mock';\n\nexport type Property = string | symbol;\n\nexport interface ProxyTraps {\n /**\n * Called when accessing any property on an object, except for\n * `.call`, `.apply` and `.bind`.\n */\n property: (property: Property) => unknown;\n\n /**\n * Called when calling a function.\n *\n * @example\n * ```\n * fn(...args)\n * ```\n *\n * @example\n * ```\n * fn.call(this, ...args)\n * ```\n *\n * @example\n * ```\n * fn.apply(this, [...args])\n * ```\n *\n * @example\n * ```\n * Reflect.apply(fn, this, [...args])\n * ```\n */\n apply: (args: unknown[]) => unknown;\n\n /**\n * Called when getting the proxy's own enumerable keys.\n *\n * @example\n * ```\n * Object.keys(proxy);\n * ```\n *\n * @example\n * ```\n * const foo = { ...proxy };\n * ```\n */\n ownKeys: () => Property[];\n}\n\nexport const createProxy = <T>(traps: ProxyTraps): Mock<T> =>\n // The Proxy target MUST be a function, otherwise we can't use the `apply` trap:\n // https://262.ecma-international.org/6.0/#sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n new Proxy(/* istanbul ignore next */ () => {}, {\n get: (target, prop: string | symbol) => {\n if (prop === 'bind') {\n return (thisArg: unknown, ...args: unknown[]) =>\n (...moreArgs: unknown[]) =>\n traps.apply([...args, ...moreArgs]);\n }\n\n if (prop === 'apply') {\n return (thisArg: unknown, args: unknown[] | undefined) =>\n traps.apply(args || []);\n }\n\n if (prop === 'call') {\n return (thisArg: unknown, ...args: unknown[]) => traps.apply(args);\n }\n\n return traps.property(prop);\n },\n\n apply: (target, thisArg: unknown, args: unknown[]) => traps.apply(args),\n\n ownKeys: () => traps.ownKeys(),\n\n getOwnPropertyDescriptor(\n target: () => void,\n prop: string | symbol\n ): PropertyDescriptor | undefined {\n const keys = traps.ownKeys();\n\n if (keys.includes(prop)) {\n return {\n configurable: true,\n enumerable: true,\n };\n }\n\n return undefined;\n },\n }) as unknown as Mock<T>;\n","import { NestedWhen } from '../errors/api';\nimport { ApplyProp } from '../expectation/expectation';\nimport type { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport type { Property } from '../proxy';\nimport { createProxy } from '../proxy';\nimport type { ExpectationBuilder } from '../when/expectation-builder';\nimport { setActiveMock } from './map';\nimport type { Mock } from './mock';\nimport { Mode } from './mock';\n\nexport const createStub = <T>(\n repo: ExpectationRepository,\n builder: ExpectationBuilder,\n getCurrentMode: () => Mode\n): Mock<T> => {\n const stub = createProxy<T>({\n property: (property) => {\n if (getCurrentMode() === Mode.CALL) {\n return repo.get(property);\n }\n\n setActiveMock(stub);\n\n builder.setProperty(property);\n\n return createProxy({\n property: (childProp: Property) => {\n throw new NestedWhen(property, childProp);\n },\n apply: (args: unknown[]) => {\n builder.setArgs(args);\n },\n ownKeys: () => {\n throw new Error('Spreading during an expectation is not supported.');\n },\n });\n },\n apply: (args: unknown[]) => {\n if (getCurrentMode() === Mode.CALL) {\n return repo.apply(args);\n }\n\n setActiveMock(stub);\n\n builder.setProperty(ApplyProp);\n builder.setArgs(args);\n\n return undefined;\n },\n ownKeys: () => {\n if (getCurrentMode() === Mode.CALL) {\n return repo.getAllProperties();\n }\n\n throw new Error('Spreading during an expectation is not supported.');\n },\n });\n\n return stub;\n};\n","import { FlexibleRepository } from '../expectation/repository/flexible-repository';\nimport { StrongExpectation } from '../expectation/strong-expectation';\nimport { isMatcher } from '../matchers/matcher';\nimport type { ExpectationFactory } from '../when/expectation-builder';\nimport { ExpectationBuilderWithFactory } from '../when/expectation-builder';\nimport type { StrongMockDefaults } from './defaults';\nimport { currentDefaults } from './defaults';\nimport { setMockState } from './map';\nimport type { MockOptions } from './options';\nimport { createStub } from './stub';\n\nexport type Mock<T> = T;\n\nconst strongExpectationFactory: ExpectationFactory = (\n property,\n args,\n returnValue,\n concreteMatcher,\n exactParams\n) =>\n new StrongExpectation(\n property,\n // Wrap every non-matcher in the default matcher.\n args?.map((arg) => (isMatcher(arg) ? arg : concreteMatcher(arg))),\n returnValue,\n exactParams\n );\n\nexport enum Mode {\n EXPECT,\n CALL,\n}\n\nlet currentMode: Mode = Mode.CALL;\n\nexport const setMode = (mode: Mode) => {\n currentMode = mode;\n};\nconst getMode = () => currentMode;\n\n/**\n * Create a type safe mock.\n *\n * @see {@link when} Set expectations on the mock using `when`.\n *\n * @param options Configure the options for this specific mock, overriding any\n * defaults that were set with {@link setDefaults}.\n * @param options.unexpectedProperty Controls what happens when an unexpected\n * property is accessed.\n * @param options.concreteMatcher The matcher that will be used when one isn't\n * specified explicitly.\n * @param options.exactParams Controls whether the number of received arguments\n * has to match the expectation.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * fn() === 23;\n */\nexport const mock = <T>({\n unexpectedProperty,\n concreteMatcher,\n exactParams,\n}: MockOptions = {}): Mock<T> => {\n const options: StrongMockDefaults = {\n unexpectedProperty:\n unexpectedProperty ?? currentDefaults.unexpectedProperty,\n concreteMatcher: concreteMatcher ?? currentDefaults.concreteMatcher,\n exactParams: exactParams ?? currentDefaults.exactParams,\n };\n\n const repository = new FlexibleRepository(options.unexpectedProperty);\n\n const builder = new ExpectationBuilderWithFactory(\n strongExpectationFactory,\n options.concreteMatcher,\n options.exactParams\n );\n\n const stub = createStub<T>(repository, builder, getMode);\n\n setMockState(stub, {\n repository,\n builder,\n options,\n });\n\n return stub;\n};\n","import type { Expectation } from '../expectation/expectation';\n\nexport interface InvocationCount {\n /**\n * Expect a call to be made at least `min` times and at most `max` times.\n */\n between: (min: number, max: number) => void;\n\n /**\n * Expect a call to be made exactly `exact` times.\n *\n * Shortcut for `between(exact, exact)`.\n */\n times: (exact: number) => void;\n\n /**\n * Expect a call to be made any number of times, including never.\n *\n * Shortcut for `between(0, Infinity)`.\n */\n anyTimes: () => void;\n\n /**\n * Expect a call to be made at least `min` times.\n *\n * Shortcut for `between(min, Infinity)`.\n */\n atLeast: (min: number) => void;\n\n /**\n * Expect a call to be made at most `max` times.\n *\n * Shortcut for `between(0, max)`.\n */\n atMost: (max: number) => void;\n\n /**\n * Expect a call to be made exactly once.\n *\n * Shortcut for `times(1)`.\n */\n once: () => void;\n\n /**\n * Expect a call to be made exactly twice.\n *\n * Shortcut for `times(2)`.\n */\n twice: () => void;\n}\n\nexport const createInvocationCount = (\n expectation: Expectation\n): InvocationCount => ({\n between(min: number, max: number) {\n expectation.setInvocationCount(min, max);\n },\n\n /* istanbul ignore next */\n times(exact: number) {\n expectation.setInvocationCount(exact, exact);\n },\n\n /* istanbul ignore next */\n anyTimes(): void {\n expectation.setInvocationCount(0, 0);\n },\n\n /* istanbul ignore next */\n atLeast(min: number) {\n expectation.setInvocationCount(min, Infinity);\n },\n\n /* istanbul ignore next */\n atMost(max: number) {\n expectation.setInvocationCount(0, max);\n },\n\n /* istanbul ignore next */\n once() {\n expectation.setInvocationCount(1, 1);\n },\n\n /* istanbul ignore next */\n twice() {\n expectation.setInvocationCount(2, 2);\n },\n /* eslint-enable no-param-reassign, no-multi-assign */\n});\n","import type { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport type { ReturnValue } from '../expectation/repository/return-value';\nimport type { ExpectationBuilder } from '../when/expectation-builder';\nimport type { InvocationCount } from './invocation-count';\nimport { createInvocationCount } from './invocation-count';\n\nexport type PromiseStub<R, P> = {\n /**\n * Set the return value for the current call.\n *\n * @param value This needs to be of the same type as the value returned\n * by the call inside `when`.\n *\n * @example\n * when(() => fn()).thenReturn(Promise.resolve(23));\n *\n * @example\n * when(() => fn()).thenReturn(Promise.reject({ foo: 'bar' });\n */\n thenReturn: (value: P) => InvocationCount;\n\n /**\n * Set the return value for the current call.\n *\n * @param promiseValue This needs to be of the same type as the value inside\n * the promise returned by the `when` callback.\n *\n * @example\n * when(() => fn()).thenResolve('foo');\n */\n thenResolve: (promiseValue: R) => InvocationCount;\n\n /**\n * Make the current call reject with the given error.\n *\n * @param error An `Error` instance. You can pass just a message, and\n * it will be wrapped in an `Error` instance. If you want to reject with\n * a non error then use the {@link thenReturn} method.\n *\n * @example\n * when(() => fn()).thenReject(new Error('oops'));\n */\n thenReject: ((error: Error) => InvocationCount) &\n ((message: string) => InvocationCount) &\n (() => InvocationCount);\n};\n\nexport type NonPromiseStub<R> = {\n /**\n * Set the return value for the current call.\n *\n * @param returnValue This needs to be of the same type as the value returned\n * by the `when` callback.\n */\n thenReturn: (returnValue: R) => InvocationCount;\n\n /**\n * Make the current call throw the given error.\n *\n * @param error The error instance. If you want to throw a simple `Error`\n * you can pass just the message.\n */\n thenThrow: ((error: Error) => InvocationCount) &\n ((message: string) => InvocationCount) &\n (() => InvocationCount);\n};\n\nconst finishExpectation = (\n returnValue: ReturnValue,\n builder: ExpectationBuilder,\n repo: ExpectationRepository\n) => {\n const finishedExpectation = builder.finish(returnValue);\n\n repo.add(finishedExpectation);\n\n return createInvocationCount(finishedExpectation);\n};\n\nconst getError = (errorOrMessage: Error | string | undefined): Error => {\n if (typeof errorOrMessage === 'string') {\n return new Error(errorOrMessage);\n }\n\n if (errorOrMessage instanceof Error) {\n return errorOrMessage;\n }\n\n return new Error();\n};\n\nexport const createReturns = (\n builder: ExpectationBuilder,\n repository: ExpectationRepository\n) => ({\n thenReturn: (returnValue: any): InvocationCount =>\n finishExpectation(\n // This will handle both thenReturn(23) and thenReturn(Promise.resolve(3)).\n { value: returnValue, isError: false, isPromise: false },\n builder,\n repository\n ),\n thenThrow: (errorOrMessage?: Error | string): InvocationCount =>\n finishExpectation(\n { value: getError(errorOrMessage), isError: true, isPromise: false },\n builder,\n repository\n ),\n thenResolve: (promiseValue: any): InvocationCount =>\n finishExpectation(\n {\n value: promiseValue,\n isError: false,\n isPromise: true,\n },\n builder,\n repository\n ),\n\n thenReject: (errorOrMessage?: Error | string): InvocationCount =>\n finishExpectation(\n {\n value: getError(errorOrMessage),\n isError: true,\n isPromise: true,\n },\n builder,\n repository\n ),\n});\n","import { getActiveMock, getMockState } from '../mock/map';\nimport { Mode, setMode } from '../mock/mock';\nimport type { NonPromiseStub, PromiseStub } from '../return/returns';\nimport { createReturns } from '../return/returns';\n\ninterface When {\n <R>(expectation: () => Promise<R>): PromiseStub<R, Promise<R>>;\n <R>(expectation: () => R): NonPromiseStub<R>;\n}\n\n/**\n * Set an expectation on a mock.\n *\n * The expectation must be finished by setting a return value, even if the value\n * is `undefined`.\n *\n * If a call happens that was not expected then the mock will throw an error.\n * By default, the call is expected to only be made once. Use the invocation\n * count helpers to expect a call multiple times.\n *\n * @param expectation A callback to set the expectation on your mock. The\n * callback must return the value from the mock to properly infer types.\n *\n * @example\n * const fn = mock<() => void>();\n * when(() => fn()).thenReturn(undefined);\n *\n * @example\n * const fn = mock<() => number>();\n * when(() => fn()).thenReturn(42).atMost(3);\n *\n * @example\n * const fn = mock<(x: number) => Promise<number>();\n * when(() => fn(23)).thenResolve(42);\n */\nexport const when: When = <R>(expectation: () => R) => {\n setMode(Mode.EXPECT);\n expectation();\n setMode(Mode.CALL);\n\n const { builder, repository } = getMockState(getActiveMock());\n\n return createReturns(builder, repository);\n};\n","import { getAllMocks, getMockState } from '../mock/map';\nimport type { Mock } from '../mock/mock';\n\n/**\n * Remove any remaining expectations on the given mock.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * reset(fn);\n *\n * fn(); // throws\n */\nexport const reset = (mock: Mock<any>): void => {\n getMockState(mock).repository.clear();\n};\n\n/**\n * Reset all existing mocks.\n *\n * @see reset\n */\nexport const resetAll = (): void => {\n getAllMocks().forEach(([mock]) => {\n reset(mock);\n });\n};\n","import { DIM_COLOR } from 'jest-matcher-utils';\nimport type { Expectation } from '../expectation/expectation';\nimport type { CallMap } from '../expectation/repository/expectation-repository';\nimport { printCall, printRemainingExpectations } from '../print';\n\nexport class UnmetExpectations extends Error {\n constructor(expectations: Expectation[]) {\n super(\n DIM_COLOR(`There are unmet expectations:\n\n - ${expectations.map((e) => e.toString()).join('\\n - ')}`)\n );\n }\n}\n\n/**\n * Merge property accesses and method calls for the same property\n * into a single call.\n *\n * @example\n * mergeCalls({ getData: [{ arguments: undefined }, { arguments: [1, 2, 3] }] }\n * // returns { getData: [{ arguments: [1, 2, 3] } }\n */\nconst mergeCalls = (callMap: CallMap): CallMap =>\n new Map(\n Array.from(callMap.entries()).map(([property, calls]) => {\n const hasMethodCalls = calls.some((call) => call.arguments);\n const hasPropertyAccesses = calls.some((call) => !call.arguments);\n\n if (hasMethodCalls && hasPropertyAccesses) {\n return [property, calls.filter((call) => call.arguments)];\n }\n\n return [property, calls];\n })\n );\n\nexport class UnexpectedCalls extends Error {\n constructor(unexpectedCalls: CallMap, expectations: Expectation[]) {\n const printedCalls = Array.from(mergeCalls(unexpectedCalls).entries())\n .map(([property, calls]) =>\n calls.map((call) => printCall(property, call.arguments)).join('\\n - ')\n )\n .join('\\n - ');\n\n super(\n DIM_COLOR(`The following calls were unexpected:\n\n - ${printedCalls}\n\n${printRemainingExpectations(expectations)}`)\n );\n }\n}\n","import { UnexpectedCalls, UnmetExpectations } from '../errors/verify';\nimport type { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport { getAllMocks, getMockState } from '../mock/map';\nimport type { Mock } from '../mock/mock';\n\nexport const verifyRepo = (repository: ExpectationRepository) => {\n const unmetExpectations = repository.getUnmet();\n\n if (unmetExpectations.length) {\n throw new UnmetExpectations(unmetExpectations);\n }\n\n const callStats = repository.getCallStats();\n\n if (callStats.unexpected.size) {\n throw new UnexpectedCalls(callStats.unexpected, unmetExpectations);\n }\n};\n\n/**\n * Verify that all expectations on the given mock have been met.\n *\n * @throws Will throw if there are remaining expectations that were set\n * using `when` and that weren't met.\n *\n * @throws Will throw if any unexpected calls happened. Normally those\n * calls throw on their own, but the error might be caught by the code\n * being tested.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * verify(fn); // throws\n */\nexport const verify = <T>(mock: Mock<T>): void => {\n const { repository } = getMockState(mock);\n\n verifyRepo(repository);\n};\n\n/**\n * Verify all existing mocks.\n *\n * @see verify\n */\nexport const verifyAll = (): void => {\n getAllMocks().forEach(([mock]) => {\n verify(mock);\n });\n};\n","import { printValue } from '../print';\nimport type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\n/**\n * Compare values using `Object.is`.\n *\n * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n *\n * @see It.deepEquals A matcher that uses deep equality.\n */\nexport const is = <T = unknown>(expected: T): TypeMatcher<T> =>\n matches((actual) => Object.is(actual, expected), {\n toString: () => `${printValue(expected)}`,\n getDiff: (actual) => ({ actual, expected }),\n });\n","import type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\n/**\n * Match any value, including `undefined` and `null`.\n *\n * @example\n * const fn = mock<(x: number, y: string) => number>();\n * when(() => fn(It.isAny(), It.isAny())).thenReturn(1);\n *\n * fn(23, 'foobar') === 1\n */\nexport const isAny = (): TypeMatcher<any> =>\n matches(() => true, {\n toString: () => 'Matcher<any>',\n });\n","import { printValue } from '../print';\nimport { deepEquals } from './deep-equals';\nimport type { TypeMatcher } from './matcher';\nimport { isMatcher, matches } from './matcher';\n\n/**\n * Match an array.\n *\n * Supports nested matchers.\n *\n * @param containing If given, the matched array has to contain ALL of these\n * elements in ANY order.\n *\n * @example\n * const fn = mock<(arr: number[]) => number>();\n * when(() => fn(It.isArray())).thenReturn(1);\n * when(() => fn(It.isArray([2, 3]))).thenReturn(2);\n *\n * fn({ length: 1, 0: 42 }) // throws\n * fn([]) === 1\n * fn([3, 2, 1]) === 2\n *\n * @example\n * It.isArray([It.isString({ containing: 'foobar' })])\n */\nexport const isArray = <T extends unknown[]>(containing?: T): TypeMatcher<T> =>\n matches(\n (actual) => {\n if (!Array.isArray(actual)) {\n return false;\n }\n\n if (!containing) {\n return true;\n }\n\n return containing.every(\n (x) =>\n actual.find((y) => {\n if (isMatcher(x)) {\n return x.matches(y);\n }\n\n return deepEquals(x).matches(y);\n }) !== undefined\n );\n },\n {\n toString: () =>\n containing ? `array(${printValue(containing)})` : 'array',\n getDiff: (actual) => {\n if (containing) {\n return {\n actual,\n expected: `Matcher<array>([${containing\n .map((value) => {\n if (isMatcher(value)) {\n return value.toString();\n }\n\n return value;\n })\n .join(', ')}])`,\n };\n }\n\n return {\n actual: `${printValue(actual)} (${typeof actual})`,\n expected: 'Matcher<array>',\n };\n },\n }\n );\n","import { printValue } from '../print';\nimport type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\n/**\n * Match any number.\n *\n * @example\n * const fn = mock<(x: number) => number>();\n * when(() => fn(It.isNumber())).returns(42);\n *\n * fn(20.5) === 42\n * fn(NaN) // throws\n */\nexport const isNumber = (): TypeMatcher<number> =>\n matches((actual) => typeof actual === 'number' && !Number.isNaN(actual), {\n toString: () => 'Matcher<number>',\n getDiff: (actual) => ({\n actual: `${printValue(actual)} (${typeof actual})`,\n expected: 'Matcher<number>',\n }),\n });\n","import { cloneDeepWith, isPlainObject } from 'lodash';\nimport { printValue } from '../print';\nimport type { Property } from '../proxy';\nimport { deepEquals } from './deep-equals';\nimport type { TypeMatcher } from './matcher';\nimport { isMatcher, matches } from './matcher';\n\ntype ObjectType = Record<Property, unknown>;\n\ntype DeepPartial<T> = T extends ObjectType\n ? { [K in keyof T]?: DeepPartial<T[K]> }\n : T;\n\nconst looksLikeObject = (value: unknown): value is ObjectType =>\n isPlainObject(value);\n\nconst getExpectedObjectDiff = (actual: unknown, expected: ObjectType): object =>\n Object.fromEntries(\n Reflect.ownKeys(expected).map((key) => {\n const right = expected[key];\n // @ts-expect-error because we're fine with a runtime undefined\n const left = actual?.[key];\n\n if (isMatcher(right)) {\n return [key, right.getDiff(left).expected];\n }\n\n if (looksLikeObject(right)) {\n return [key, getExpectedObjectDiff(left, right)];\n }\n\n return [key, right];\n })\n );\n\nconst getActualObjectDiff = (\n actual: unknown,\n expected: ObjectType\n): unknown => {\n if (!looksLikeObject(actual)) {\n return actual;\n }\n\n return Object.fromEntries(\n Reflect.ownKeys(expected).map((key) => {\n const right = expected[key];\n const left = actual[key];\n\n if (!left) {\n return [];\n }\n\n if (isMatcher(right)) {\n return [key, right.getDiff(left).actual];\n }\n\n if (looksLikeObject(right)) {\n return [key, getActualObjectDiff(left, right)];\n }\n\n return [key, left];\n })\n );\n};\n\nconst isMatch = (actual: unknown, expected: ObjectType): boolean =>\n Reflect.ownKeys(expected).every((key) => {\n const right = expected[key];\n const left = looksLikeObject(actual) ? actual[key] : undefined;\n\n if (!left) {\n return false;\n }\n\n if (isMatcher(right)) {\n return right.matches(left);\n }\n\n if (looksLikeObject(right)) {\n return isMatch(left, right);\n }\n\n return deepEquals(right).matches(left);\n });\n\nconst deepPrintObject = (value: ObjectType) =>\n cloneDeepWith(value, (value) => {\n if (isMatcher(value)) {\n return value.toString();\n }\n\n return undefined;\n });\n\n/**\n * Match any plain object.\n *\n * Object like values, e.g. classes and arrays, will not be matched.\n *\n * @param partial An optional subset of the expected object that will be\n * recursively matched. Supports nested matchers. Values will be\n * compared with {@link deepEquals}.\n *\n * @example\n * const fn = mock<(pos: { x: number, y: number }) => number>();\n * when(() => fn(It.isObject({ x: 23 }))).returns(42);\n *\n * fn({ x: 100, y: 200 }) // throws\n * fn({ x: 23, y: 200 }) // returns 42\n *\n * @example\n * It.isObject({ foo: It.isString() })\n */\nexport const isObject = <T extends ObjectType, K extends DeepPartial<T>>(\n partial?: K\n): TypeMatcher<T> =>\n matches(\n (actual) => {\n if (!looksLikeObject(actual)) {\n return false;\n }\n\n if (!partial) {\n return true;\n }\n\n return isMatch(actual, partial);\n },\n {\n toString: () => {\n if (!partial) {\n return 'Matcher<object>';\n }\n\n return `Matcher<object>(${printValue(deepPrintObject(partial))})`;\n },\n getDiff: (actual) => {\n if (!partial) {\n return {\n expected: 'Matcher<object>',\n actual: `${printValue(actual)}`,\n };\n }\n\n return {\n actual: getActualObjectDiff(actual, partial),\n expected: getExpectedObjectDiff(actual, partial),\n };\n },\n }\n );\n","import type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\n/**\n * Match any string.\n *\n * @param matching An optional string or RegExp to match the string against.\n * If it's a string, a case-sensitive search will be performed.\n *\n * @example\n * const fn = mock<(x: string, y: string) => number>();\n * when(() => fn(It.isString(), It.isString('bar'))).returns(42);\n *\n * fn('foo', 'baz') // throws\n * fn('foo', 'bar') === 42\n */\nexport const isString = (matching?: string | RegExp): TypeMatcher<string> =>\n matches(\n (actual) => {\n if (typeof actual !== 'string') {\n return false;\n }\n\n if (!matching) {\n return true;\n }\n\n if (typeof matching === 'string') {\n return actual.indexOf(matching) !== -1;\n }\n\n return matching.test(actual);\n },\n {\n toString: () => {\n if (matching) {\n return `Matcher<string>(${matching})`;\n }\n\n return 'Matcher<string>';\n },\n getDiff: (actual) => {\n if (matching) {\n return {\n expected: `Matcher<string>(${matching})`,\n actual,\n };\n }\n\n return {\n expected: 'Matcher<string>',\n actual: `${actual} (${typeof actual})`,\n };\n },\n }\n );\n","import type { Matcher, TypeMatcher } from './matcher';\nimport { MATCHER_SYMBOL } from './matcher';\n\n/**\n * Matches anything and stores the received value.\n *\n * This should not be needed for most cases, but can be useful if you need\n * access to a complex argument outside the expectation e.g. to test a\n * callback.\n *\n * @param name If given, this name will be printed in error messages.\n *\n * @example\n * const fn = mock<(cb: (value: number) => number) => void>();\n * const matcher = It.willCapture();\n * when(() => fn(matcher)).thenReturn();\n *\n * fn(x => x + 1);\n * matcher.value?.(3) === 4\n */\nexport const willCapture = <T = unknown>(\n name?: string\n): TypeMatcher<T> & {\n value: T | undefined;\n} => {\n let capturedValue: T | undefined;\n\n const matcher: Matcher & {\n value: T | undefined;\n } = {\n [MATCHER_SYMBOL]: true,\n matches: (actual) => {\n capturedValue = actual;\n\n return true;\n },\n toString: () => (name ? `Capture(${name})` : 'Capture'),\n getDiff: (actual) => ({\n actual,\n expected: actual,\n }),\n get value(): T | undefined {\n return capturedValue;\n },\n };\n\n return matcher as any;\n};\n","/* istanbul ignore file */\nexport { deepEquals } from './deep-equals';\n\nexport { is } from './is';\n\nexport { isAny } from './is-any';\n\nexport { isArray } from './is-array';\n\nexport { isNumber } from './is-number';\n\nexport { isObject } from './is-object';\n\nexport { isString } from './is-string';\n\nexport { matches } from './matcher';\n\nexport { willCapture } from './will-capture';\n"],"names":["ApplyProp","Symbol","MATCHER_SYMBOL","isMatcher","f","getMatcherDiffs","matchers","args","matcherDiffs","map","matcher","i","getDiff","actual","d","expected","matches","predicate","options","toString","printProperty","property","printValue","arg","stringify","printArgs","join","printCall","prettyProperty","prettyArgs","RECEIVED_COLOR","printReturns","isError","isPromise","value","min","max","thenPrefix","printWhen","EXPECTED_COLOR","printExpectation","returnValue","printRemainingExpectations","expectations","length","e","UnexpectedAccess","Error","constructor","DIM_COLOR","printArgsDiff","diff","printDiff","omitAnnotationLines","ansilessDiffLines","stripAnsi","split","relevantDiffLines","slice","lastLine","coloredDiffLines","line","first","charAt","printExpectationDiff","printDiffForAllExpectations","undefined","filter","x","UnexpectedCall","header","propertyExpectations","matcherResult","UnexpectedProperty","unboxReturnValue","Promise","reject","resolve","FlexibleRepository","unexpectedProperty","THROW","Map","expectedCallStats","unexpectedCallStats","apply","get","handlePropertyWithMatchingExpectations","recordExpected","propertyExpectation","find","expectation","countAndConsume","callExpectation","getValueForUnexpectedCall","handlePropertyWithNoExpectations","toStringTag","getValueForUnexpectedAccess","add","set","matchCount","clear","getAllProperties","Array","from","keys","getCallStats","unexpected","getUnmet","concat","values","calls","arguments","recordUnexpected","consumeExpectation","StrongExpectation","exactParams","matched","setInvocationCount","matchesArgs","isUnmet","received","every","UnfinishedExpectation","MissingWhen","NotAMock","NestedWhen","parentProp","childProp","snippet","ExpectationBuilderWithFactory","createExpectation","concreteMatcher","setProperty","setArgs","finish","removeUndefined","object","isArray","isObjectLike","omitBy","isUndefined","deepEquals","strict","isEqual","defaults","CALL_THROW","currentDefaults","setDefaults","newDefaults","activeMock","setActiveMock","mock","getActiveMock","mockMap","getMockState","has","setMockState","state","getAllMocks","entries","createProxy","traps","Proxy","target","prop","thisArg","moreArgs","ownKeys","getOwnPropertyDescriptor","includes","configurable","enumerable","createStub","repo","builder","getCurrentMode","stub","Mode","CALL","strongExpectationFactory","currentMode","setMode","mode","getMode","repository","createInvocationCount","between","times","exact","anyTimes","atLeast","Infinity","atMost","once","twice","finishExpectation","finishedExpectation","getError","errorOrMessage","createReturns","thenReturn","thenThrow","thenResolve","promiseValue","thenReject","when","EXPECT","reset","resetAll","forEach","UnmetExpectations","mergeCalls","callMap","hasMethodCalls","some","call","hasPropertyAccesses","UnexpectedCalls","unexpectedCalls","printedCalls","verifyRepo","unmetExpectations","callStats","size","verify","verifyAll","is","Object","isAny","containing","y","isNumber","Number","isNaN","looksLikeObject","isPlainObject","getExpectedObjectDiff","fromEntries","Reflect","key","right","left","getActualObjectDiff","isMatch","deepPrintObject","cloneDeepWith","isObject","partial","isString","matching","indexOf","test","willCapture","name","capturedValue"],"mappings":";;;;;;;;;AAgCA;;;AAGO,MAAMA,SAAS,GAAGC,MAAM,CAAC,OAAD,CAAxB;;ACnCA,MAAMC,cAAc,GAAGD,MAAM,CAAC,SAAD,CAA7B;AAgEP;;;;SAGgBE,UAAUC;AACxB,SAAO,CAAC,EAAEA,CAAC,IAAcA,CAAE,CAACF,cAAD,CAAnB,CAAR;AACD;AAEM,MAAMG,eAAe,GAAG,CAC7BC,QAD6B,EAE7BC,IAF6B;AAI7B,QAAMC,YAAY,GAAGF,QAAQ,CAACG,GAAT,CAAa,CAACC,OAAD,EAAUC,CAAV,KAAgBD,OAAO,CAACE,OAAR,CAAgBL,IAAI,CAACI,CAAD,CAApB,CAA7B,CAArB;AACA,QAAME,MAAM,GAAGL,YAAY,CAACC,GAAb,CAAkBK,CAAD,IAAOA,CAAC,CAACD,MAA1B,CAAf;AACA,QAAME,QAAQ,GAAGP,YAAY,CAACC,GAAb,CAAkBK,CAAD,IAAOA,CAAC,CAACC,QAA1B,CAAjB;AAEA,SAAO;AAAEF,IAAAA,MAAF;AAAUE,IAAAA;AAAV,GAAP;AACD,CATM;AAWP;;;;;;;;;;;;;;;;;;;;;;;AAsBO,MAAMC,OAAO,GAAG,CACrBC,SADqB,EAErBC,OAFqB;;;AAIrB;AACA;AACA,QAAMC,QAAQ,wBACZD,OADY,oBACZA,OAAO,CAAEC,QADG,gCACU,iBAAiBF,SAAS,CAACE,QAAV,KADzC;AAEA,QAAMP,OAAO,uBACXM,OADW,oBACXA,OAAO,CAAEN,OADE,+BAETC,MAAD,KAAa;AACZA,IAAAA,MADY;AAEZE,IAAAA,QAAQ,EA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;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/expectation/expectation.ts","../src/matchers/matcher.ts","../src/print.ts","../src/errors/unexpected-access.ts","../src/errors/diff.ts","../src/errors/unexpected-call.ts","../src/mock/options.ts","../src/expectation/repository/return-value.ts","../src/expectation/repository/flexible-repository.ts","../src/expectation/strong-expectation.ts","../src/errors/api.ts","../src/when/expectation-builder.ts","../src/matchers/deep-equals.ts","../src/mock/defaults.ts","../src/mock/map.ts","../src/proxy.ts","../src/mock/stub.ts","../src/mock/mock.ts","../src/return/invocation-count.ts","../src/return/returns.ts","../src/when/when.ts","../src/verify/reset.ts","../src/errors/verify.ts","../src/verify/verify.ts","../src/matchers/is.ts","../src/matchers/is-any.ts","../src/matchers/is-array.ts","../src/matchers/is-number.ts","../src/matchers/is-plain-object.ts","../src/matchers/is-partial.ts","../src/matchers/is-string.ts","../src/matchers/will-capture.ts","../src/matchers/it.ts"],"sourcesContent":["import type { Matcher } from '../matchers/matcher';\nimport type { Property } from '../proxy';\nimport type { ReturnValue } from './repository/return-value';\n\n/**\n * Compare received arguments against matchers.\n */\nexport interface Expectation {\n property: Property;\n\n /**\n * `undefined` means this is a property expectation.\n * `[]` means this is a function call with no arguments.\n */\n args: Matcher[] | undefined;\n\n returnValue: ReturnValue;\n\n min: number;\n\n max: number;\n\n /**\n * How many times should this expectation match?\n */\n setInvocationCount: (min: number, max: number) => void;\n\n matches: (args: unknown[] | undefined) => boolean;\n\n toString: () => string;\n}\n\n/**\n * Special symbol denoting the call of a function.\n */\nexport const ApplyProp = Symbol('apply');\n","export const MATCHER_SYMBOL = Symbol('matcher');\n\nexport type MatcherDiffer = (actual: any) => { actual: any; expected: any };\n\nexport type MatcherOptions = {\n /**\n * Will be called when printing the diff between an expectation and the\n * (mismatching) received arguments.\n *\n * With this function you can pretty print the `actual` and `expected` values\n * according to your matcher's logic.\n *\n * @param actual The actual value received by this matcher, same as the one\n * in `matches`.\n *\n * @example\n * const neverMatcher = It.matches(() => false, {\n * getDiff: (actual) => ({ actual, expected: 'never' })\n * });\n *\n * when(() => fn(neverMatcher)).thenReturn(42);\n *\n * fn(42);\n * // - Expected\n * // + Received\n * //\n * // - 'never'\n * // + 42\n */\n getDiff: MatcherDiffer;\n\n /**\n * Will be called when printing arguments for an unexpected or unmet expectation.\n *\n * @example\n * const neverMatcher = It.matches(() => false, {\n * toString: () => 'never'\n * });\n * when(() => fn(neverMatcher)).thenReturn(42);\n *\n * fn(42);\n * // Unmet expectations:\n * // when(() => fn(never)).thenReturn(42)\n */\n toString: () => string;\n};\n\n/**\n * You MUST use {@link It.matches} to create this branded type.\n */\nexport interface Matcher extends MatcherOptions {\n [MATCHER_SYMBOL]: boolean;\n\n /**\n * Will be called with the received value and should return whether it matches\n * the expectation.\n */\n matches: (actual: any) => boolean;\n}\n\n/**\n * This takes the shape of T to satisfy call sites, but strong-mock will only\n * care about the matcher type.\n */\nexport type TypeMatcher<T> = T & Matcher;\n\n/**\n * Used to test if an expectation is an argument is a custom matcher.\n */\nexport function isMatcher(f: unknown): f is Matcher {\n return !!(f && (<Matcher>f)[MATCHER_SYMBOL]);\n}\n\nexport const getMatcherDiffs = (\n matchers: Matcher[],\n args: unknown[]\n): { actual: unknown[]; expected: unknown[] } => {\n const matcherDiffs = matchers.map((matcher, i) => matcher.getDiff(args[i]));\n const actual = matcherDiffs.map((d) => d.actual);\n const expected = matcherDiffs.map((d) => d.expected);\n\n return { actual, expected };\n};\n\n/**\n * Create a custom matcher.\n *\n * @param predicate Will receive the actual value and return whether it matches the expectation.\n * @param options\n * @param options.toString An optional function that should return a string that will be\n * used when the matcher needs to be printed in an error message. By default,\n * it stringifies `predicate`.\n * @param options.getDiff An optional function that will be called when printing the\n * diff for a failed expectation. It will only be called if there's a mismatch\n * between the expected and received values i.e. `predicate(actual)` fails.\n * By default, the `toString` method will be used to format the expected value,\n * while the received value will be returned as-is.\n *\n * @example\n * // Create a matcher for positive numbers.\n * const fn = mock<(x: number) => number>();\n * when(() => fn(It.matches(x => x >= 0))).thenReturn(42);\n *\n * fn(2) === 42\n * fn(-1) // throws\n */\nexport const matches = <T>(\n predicate: (actual: T) => boolean,\n options?: Partial<MatcherOptions>\n): TypeMatcher<T> => {\n // We can't use destructuring with default values because `options` is optional,\n // so it needs a default value of `{}`, which will come with a native `toString`.\n const toString =\n options?.toString ?? (() => `Matcher(${predicate.toString()})`);\n const getDiff =\n options?.getDiff ??\n ((actual) => ({\n actual,\n expected: toString(),\n }));\n\n const matcher: Matcher = {\n [MATCHER_SYMBOL]: true,\n matches: (actual: T) => predicate(actual),\n toString,\n getDiff: (actual) => {\n if (predicate(actual)) {\n return {\n actual,\n expected: actual,\n };\n }\n\n return getDiff(actual);\n },\n };\n\n return matcher as any;\n};\n","import { EXPECTED_COLOR, RECEIVED_COLOR, stringify } from 'jest-matcher-utils';\nimport type { Expectation } from './expectation/expectation';\nimport { ApplyProp } from './expectation/expectation';\nimport type { ReturnValue } from './expectation/repository/return-value';\nimport { isMatcher } from './matchers/matcher';\nimport type { Property } from './proxy';\n\nexport const printProperty = (property: Property) => {\n if (property === ApplyProp) {\n return '';\n }\n\n if (typeof property === 'symbol') {\n return `[${property.toString()}]`;\n }\n\n return `.${property}`;\n};\n\nexport const printValue = (arg: unknown): string => {\n // Call toString on matchers directly to avoid wrapping strings returned by them in quotes.\n if (isMatcher(arg)) {\n return arg.toString();\n }\n\n return stringify(arg);\n};\n\nconst printArgs = (args: any[]) =>\n args.map((arg) => printValue(arg)).join(', ');\n\nexport const printCall = (property: Property, args?: any[]) => {\n const prettyProperty = printProperty(property);\n\n if (args) {\n const prettyArgs = printArgs(args);\n\n return `mock${RECEIVED_COLOR(`${prettyProperty}(${prettyArgs})`)}`;\n }\n\n return `mock${RECEIVED_COLOR(`${prettyProperty}`)}`;\n};\n\nexport const printReturns = (\n { isError, isPromise, value }: ReturnValue,\n min: number,\n max: number\n) => {\n let thenPrefix = '';\n\n if (isPromise) {\n if (isError) {\n thenPrefix += 'thenReject';\n } else {\n thenPrefix += 'thenResolve';\n }\n } else if (isError) {\n thenPrefix += 'thenThrow';\n } else {\n thenPrefix += 'thenReturn';\n }\n\n return `.${thenPrefix}(${RECEIVED_COLOR(\n printValue(value)\n )}).between(${min}, ${max})`;\n};\n\nexport const printWhen = (property: Property, args: any[] | undefined) => {\n const prettyProperty = printProperty(property);\n\n if (args) {\n return `when(() => mock${EXPECTED_COLOR(\n `${prettyProperty}(${printArgs(args)})`\n )})`;\n }\n\n return `when(() => mock${EXPECTED_COLOR(`${printProperty(property)}`)})`;\n};\n\nexport const printExpectation = (\n property: Property,\n args: any[] | undefined,\n returnValue: ReturnValue,\n min: number,\n max: number\n) => `${printWhen(property, args)}${printReturns(returnValue, min, max)}`;\n\nexport const printRemainingExpectations = (expectations: Expectation[]) =>\n expectations.length\n ? `Remaining unmet expectations:\n - ${expectations.map((e) => e.toString()).join('\\n - ')}`\n : 'There are no remaining unmet expectations.';\n","import { DIM_COLOR } from 'jest-matcher-utils';\nimport type { Expectation } from '../expectation/expectation';\nimport { printCall, printRemainingExpectations } from '../print';\nimport type { Property } from '../proxy';\n\nexport class UnexpectedAccess extends Error {\n constructor(property: Property, expectations: Expectation[]) {\n super(\n DIM_COLOR(`Didn't expect ${printCall(property)} to be accessed.\n\nIf you expect this property to be accessed then please\nset an expectation for it.\n\n${printRemainingExpectations(expectations)}`)\n );\n }\n}\n","import { diff as printDiff } from 'jest-diff';\nimport { EXPECTED_COLOR, RECEIVED_COLOR } from 'jest-matcher-utils';\nimport stripAnsi from 'strip-ansi';\nimport type { Expectation } from '../expectation/expectation';\nimport { getMatcherDiffs } from '../matchers/matcher';\n\nexport const printArgsDiff = (\n expected: unknown[],\n actual: unknown[]\n): string => {\n const diff = printDiff(expected, actual, { omitAnnotationLines: true });\n\n /* istanbul ignore next this is not expected in practice */\n if (!diff) {\n return '';\n }\n\n const ansilessDiffLines = stripAnsi(diff).split('\\n');\n let relevantDiffLines: string[];\n\n // Strip Array [ ... ] surroundings.\n if (!expected.length) {\n // - Array []\n // + Array [\n // ...\n // ]\n relevantDiffLines = ansilessDiffLines.slice(2, -1);\n } else if (!actual.length) {\n // - Array [\n // ...\n // ]\n // + Array []\n relevantDiffLines = ansilessDiffLines.slice(1, -2);\n } else {\n // Array [\n // ...\n // ]\n relevantDiffLines = ansilessDiffLines.slice(1, -1);\n }\n\n // Strip the trailing comma.\n const lastLine = relevantDiffLines[relevantDiffLines.length - 1].slice(0, -1);\n\n const coloredDiffLines = [...relevantDiffLines.slice(0, -1), lastLine].map(\n (line) => {\n const first = line.charAt(0);\n\n switch (first) {\n case '-':\n return EXPECTED_COLOR(line);\n case '+':\n return RECEIVED_COLOR(line);\n default:\n return line;\n }\n }\n );\n\n return coloredDiffLines.join('\\n');\n};\n\nexport const printExpectationDiff = (e: Expectation, args: unknown[]) => {\n if (!e.args?.length) {\n return '';\n }\n\n const { actual, expected } = getMatcherDiffs(e.args, args);\n\n return printArgsDiff(expected, actual);\n};\n\nexport const printDiffForAllExpectations = (\n expectations: Expectation[],\n actual: unknown[]\n) =>\n expectations\n .map((e) => {\n const diff = printExpectationDiff(e, actual);\n\n if (diff) {\n return `${e.toString()}\n${EXPECTED_COLOR('- Expected')}\n${RECEIVED_COLOR('+ Received')}\n\n${diff}`;\n }\n\n return undefined;\n })\n .filter((x) => x)\n .join('\\n\\n');\n","import { DIM_COLOR } from 'jest-matcher-utils';\nimport type { Expectation } from '../expectation/expectation';\nimport { getMatcherDiffs } from '../matchers/matcher';\nimport { printCall } from '../print';\nimport type { Property } from '../proxy';\nimport { printDiffForAllExpectations } from './diff';\n\ntype MatcherResult = {\n expected: unknown;\n actual: unknown;\n};\n\n// This is taken from jest.\ninterface MatcherError {\n matcherResult?: MatcherResult;\n}\n\nexport class UnexpectedCall extends Error implements MatcherError {\n public matcherResult?: MatcherResult;\n\n constructor(\n property: Property,\n args: unknown[],\n expectations: Expectation[]\n ) {\n const header = `Didn't expect ${printCall(property, args)} to be called.`;\n\n const propertyExpectations = expectations.filter(\n (e) => e.property === property\n );\n\n if (propertyExpectations.length) {\n super(\n DIM_COLOR(`${header}\n\nRemaining expectations:\n${printDiffForAllExpectations(propertyExpectations, args)}`)\n );\n\n // If we have a single expectation we can attach the actual/expected args\n // to the error instance, so that an IDE may show its own diff for them.\n if (\n propertyExpectations.length === 1 &&\n propertyExpectations[0].args?.length\n ) {\n const { actual, expected } = getMatcherDiffs(\n propertyExpectations[0].args,\n args\n );\n this.matcherResult = {\n actual,\n expected,\n };\n }\n } else {\n super(\n DIM_COLOR(`${header}\n \nNo remaining expectations.`)\n );\n }\n }\n}\n","import type { Matcher } from '../matchers/matcher';\n\nexport type ConcreteMatcher = <T>(expected: T) => Matcher;\n\nexport enum UnexpectedProperty {\n /**\n * Throw an error immediately.\n *\n * @example\n * // Will throw \"Didn't expect foo to be accessed\".\n * const { foo } = service;\n *\n * // Will throw \"Didn't expect foo to be accessed\",\n * // without printing the arguments.\n * foo(42);\n */\n THROW,\n\n /**\n * Return a function that will throw if called. This can be useful if your\n * code destructures a function but never calls it.\n *\n * It will also improve error messages for unexpected calls because arguments\n * will be captured instead of throwing immediately on the property access.\n *\n * The function will be returned even if the property is not supposed to be a\n * function. This could cause weird behavior at runtime, when your code expects\n * e.g. a number and gets a function instead.\n *\n * @example\n * // This will NOT throw.\n * const { foo } = service;\n *\n * // This will NOT throw, and might produce unexpected results.\n * foo > 0\n *\n * // Will throw \"Didn't expect foo(42) to be called\".\n * foo(42);\n */\n CALL_THROW,\n}\n\nexport interface MockOptions {\n /**\n * Controls what should be returned for a property with no expectations.\n *\n * A property with no expectations is a property that has no `when`\n * expectations set on it. It can also be a property that ran out of `when`\n * expectations.\n *\n * The default is to return a function that will throw when called.\n *\n * @example\n * const foo = mock<{ bar: () => number }>();\n * foo.bar() // unexpected property access\n *\n * @example\n * const foo = mock<{ bar: () => number }>();\n * when(() => foo.bar()).thenReturn(42);\n * foo.bar() === 42\n * foo.bar() // unexpected property access\n */\n unexpectedProperty?: UnexpectedProperty;\n\n /**\n * If `true`, the number of received arguments in a function/method call has to\n * match the number of arguments set in the expectation.\n *\n * If `false`, extra parameters are considered optional and checked by the\n * TypeScript compiler instead.\n *\n * You may want to set this to `true` if you're not using TypeScript,\n * or if you want to be extra strict.\n *\n * @example\n * const fn = mock<(value?: number) => number>({ exactParams: true });\n * when(() => fn()).thenReturn(42);\n *\n * fn(100) // throws with exactParams, returns 42 without\n */\n exactParams?: boolean;\n\n /**\n * The matcher that will be used when one isn't specified explicitly.\n *\n * The most common use case is replacing the default {@link It.deepEquals}\n * matcher with {@link It.is}, but you can also use {@link It.matches} to\n * create a custom matcher.\n *\n * @param expected The concrete expected value received from the\n * {@link when} expectation.\n *\n * @example\n * const fn = mock<(value: number[]) => boolean>({\n * concreteMatcher: It.is\n * });\n *\n * const expected = [1, 2, 3];\n * when(() => fn(expected).thenReturn(true);\n *\n * fn([1, 2, 3]); // throws because different array instance\n * fn(expected); // OK\n */\n concreteMatcher?: ConcreteMatcher;\n}\n","export type ReturnValue = {\n value: any;\n isPromise?: boolean;\n isError?: boolean;\n};\n\n/**\n * Unbox the expectation's return value.\n *\n * If the value is an error then throw it.\n *\n * If the value is a promise then resolve/reject it.\n */\nexport const unboxReturnValue = ({\n isError,\n isPromise,\n value,\n}: ReturnValue) => {\n if (isError) {\n if (value instanceof Error) {\n if (isPromise) {\n return Promise.reject(value);\n }\n throw value;\n }\n\n if (isPromise) {\n return Promise.reject(new Error(value));\n }\n\n throw new Error(value);\n }\n\n if (isPromise) {\n return Promise.resolve(value);\n }\n\n return value;\n};\n","import { UnexpectedAccess } from '../../errors/unexpected-access';\nimport { UnexpectedCall } from '../../errors/unexpected-call';\nimport { MATCHER_SYMBOL } from '../../matchers/matcher';\nimport { UnexpectedProperty } from '../../mock/options';\nimport type { Property } from '../../proxy';\nimport type { Expectation } from '../expectation';\nimport { ApplyProp } from '../expectation';\nimport type { CallMap, ExpectationRepository } from './expectation-repository';\nimport { unboxReturnValue } from './return-value';\n\ntype CountableExpectation = {\n expectation: Expectation;\n matchCount: number;\n};\n\n/**\n * An expectation repository with a configurable behavior for\n * unexpected property access.\n */\nexport class FlexibleRepository implements ExpectationRepository {\n constructor(\n private unexpectedProperty: UnexpectedProperty = UnexpectedProperty.THROW\n ) {}\n\n protected readonly expectations = new Map<Property, CountableExpectation[]>();\n\n private readonly expectedCallStats: CallMap = new Map();\n\n private readonly unexpectedCallStats: CallMap = new Map();\n\n add(expectation: Expectation): void {\n const { property } = expectation;\n\n const expectations = this.expectations.get(property) || [];\n\n this.expectations.set(property, [\n ...expectations,\n {\n expectation,\n matchCount: 0,\n },\n ]);\n }\n\n clear(): void {\n this.expectations.clear();\n this.expectedCallStats.clear();\n this.unexpectedCallStats.clear();\n }\n\n apply = (args: unknown[]): unknown => this.get(ApplyProp)(...args);\n\n // TODO: this returns any, but the interface returns unknown\n // unknown causes errors in apply tests, and any causes bugs in bootstrapped SM\n get(property: Property): any {\n const expectations = this.expectations.get(property);\n\n if (expectations && expectations.length) {\n return this.handlePropertyWithMatchingExpectations(\n property,\n expectations\n );\n }\n\n return this.handlePropertyWithNoExpectations(property);\n }\n\n private handlePropertyWithMatchingExpectations = (\n property: Property,\n expectations: CountableExpectation[]\n ) => {\n // Avoid recording call stats for function calls, since the property is an\n // internal detail.\n if (property !== ApplyProp) {\n // An unexpected call could still happen later, if the property returns a\n // function that will not match the given args.\n this.recordExpected(property, undefined);\n }\n\n const propertyExpectation = expectations.find((e) =>\n e.expectation.matches(undefined)\n );\n\n if (propertyExpectation) {\n this.countAndConsume(propertyExpectation);\n\n return unboxReturnValue(propertyExpectation.expectation.returnValue);\n }\n\n return (...args: any[]) => {\n const callExpectation = expectations.find((e) =>\n e.expectation.matches(args)\n );\n\n if (callExpectation) {\n this.recordExpected(property, args);\n this.countAndConsume(callExpectation);\n\n return unboxReturnValue(callExpectation.expectation.returnValue);\n }\n\n return this.getValueForUnexpectedCall(property, args);\n };\n };\n\n private handlePropertyWithNoExpectations = (property: Property) => {\n switch (property) {\n case 'toString':\n return () => 'mock';\n case '@@toStringTag':\n case Symbol.toStringTag:\n case 'name':\n return 'mock';\n\n // Promise.resolve() tries to see if it's a \"thenable\".\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables\n case 'then':\n return undefined;\n\n // pretty-format\n case '$$typeof':\n case 'constructor':\n case '@@__IMMUTABLE_ITERABLE__@@':\n case '@@__IMMUTABLE_RECORD__@@':\n return null;\n\n case MATCHER_SYMBOL:\n return false;\n\n case ApplyProp:\n return (...args: any[]) =>\n this.getValueForUnexpectedCall(property, args);\n default:\n return this.getValueForUnexpectedAccess(property);\n }\n };\n\n getAllProperties(): Property[] {\n return Array.from(this.expectations.keys());\n }\n\n getCallStats() {\n return {\n expected: this.expectedCallStats,\n unexpected: this.unexpectedCallStats,\n };\n }\n\n getUnmet(): Expectation[] {\n return ([] as Expectation[]).concat(\n ...Array.from(this.expectations.values()).map((expectations) =>\n expectations\n .filter((e) => e.expectation.min > e.matchCount)\n .map((e) => e.expectation)\n )\n );\n }\n\n private recordExpected(property: Property, args: any[] | undefined) {\n const calls = this.expectedCallStats.get(property) || [];\n\n this.expectedCallStats.set(property, [...calls, { arguments: args }]);\n }\n\n private recordUnexpected(property: Property, args: any[] | undefined) {\n const calls = this.unexpectedCallStats.get(property) || [];\n\n this.unexpectedCallStats.set(property, [...calls, { arguments: args }]);\n }\n\n private countAndConsume(expectation: CountableExpectation) {\n // eslint-disable-next-line no-param-reassign\n expectation.matchCount++;\n\n this.consumeExpectation(expectation);\n }\n\n private consumeExpectation(expectation: CountableExpectation): void {\n const { property, max } = expectation.expectation;\n\n const expectations = this.expectations.get(property)!;\n\n if (expectation.matchCount === max) {\n this.expectations.set(\n property,\n expectations.filter((e) => e !== expectation)\n );\n }\n }\n\n private getValueForUnexpectedCall(property: Property, args: any[]): never {\n this.recordUnexpected(property, args);\n\n throw new UnexpectedCall(property, args, this.getUnmet());\n }\n\n private getValueForUnexpectedAccess(property: Property): unknown {\n if (this.unexpectedProperty === UnexpectedProperty.THROW) {\n this.recordUnexpected(property, undefined);\n\n throw new UnexpectedAccess(property, this.getUnmet());\n }\n\n return (...args: unknown[]) => {\n this.recordUnexpected(property, args);\n\n throw new UnexpectedCall(property, args, this.getUnmet());\n };\n }\n}\n","import type { Matcher } from '../matchers/matcher';\nimport { printExpectation } from '../print';\nimport type { Property } from '../proxy';\nimport type { Expectation } from './expectation';\nimport type { ReturnValue } from './repository/return-value';\n\n/**\n * Matches a call with more parameters than expected because it is assumed the\n * compiler will check that those parameters are optional.\n *\n * @example\n * new StrongExpectation(\n * 'bar',\n * deepEquals([1, 2, 3]),\n * 23\n * ).matches('bar', [1, 2, 3]) === true;\n */\nexport class StrongExpectation implements Expectation {\n private matched = 0;\n\n public min = 1;\n\n public max = 1;\n\n constructor(\n public property: Property,\n public args: Matcher[] | undefined,\n public returnValue: ReturnValue,\n private exactParams: boolean = false\n ) {}\n\n setInvocationCount(min: number, max = 1) {\n this.min = min;\n this.max = max;\n }\n\n matches(args: any[] | undefined): boolean {\n if (!this.matchesArgs(args)) {\n return false;\n }\n\n this.matched++;\n\n return this.max === 0 || this.matched <= this.max;\n }\n\n isUnmet(): boolean {\n return this.matched < this.min;\n }\n\n private matchesArgs(received: any[] | undefined) {\n if (this.args === undefined) {\n return !received;\n }\n\n if (!received) {\n return false;\n }\n\n if (this.exactParams) {\n if (this.args.length !== received.length) {\n return false;\n }\n }\n\n return this.args.every((arg, i) => arg.matches(received[i]));\n }\n\n toString() {\n return printExpectation(\n this.property,\n this.args,\n this.returnValue,\n this.min,\n this.max\n );\n }\n}\n","import { printProperty, printWhen } from '../print';\nimport type { Property } from '../proxy';\n\nexport class UnfinishedExpectation extends Error {\n constructor(property: Property, args: any[] | undefined) {\n super(`There is an unfinished pending expectation:\n\n${printWhen(property, args)}\n\nPlease finish it by setting a return value even if the value\nis undefined.`);\n }\n}\n\nexport class MissingWhen extends Error {\n constructor() {\n super(`You tried setting a return value without an expectation.\n\nEvery call to set a return value must be preceded by an expectation.`);\n }\n}\n\nexport class NotAMock extends Error {\n constructor() {\n super(`We couldn't find the mock.\n\nMake sure you're passing in an actual mock.`);\n }\n}\n\nexport class NestedWhen extends Error {\n constructor(parentProp: Property, childProp: Property) {\n const snippet = `\nconst parentMock = mock<T1>();\nconst childMock = mock<T2>();\n\nwhen(() => childMock${printProperty(childProp)}).thenReturn(...);\nwhen(() => parentMock${printProperty(parentProp)}).thenReturn(childMock)\n`;\n\n super(\n `Setting an expectation on a nested property is not supported.\n\nYou can return an object directly when the first property is accessed,\nor you can even return a separate mock:\n${snippet}`\n );\n }\n}\n","import { MissingWhen, UnfinishedExpectation } from '../errors/api';\nimport type { Expectation } from '../expectation/expectation';\nimport type { ReturnValue } from '../expectation/repository/return-value';\nimport type { ConcreteMatcher } from '../mock/options';\nimport type { Property } from '../proxy';\n\n/**\n * An expectation has to be built incrementally, starting first with the property\n * being accessed inside {@link createStub}, then any arguments passed to it, and ending\n * it with the returned value from {@link createReturns}.\n */\nexport interface ExpectationBuilder {\n setProperty: (prop: Property) => void;\n\n setArgs: (args: unknown[] | undefined) => void;\n\n finish: (returnValue: ReturnValue) => Expectation;\n}\n\nexport type ExpectationFactory = (\n property: Property,\n args: any[] | undefined,\n returnValue: ReturnValue,\n concreteMatcher: ConcreteMatcher,\n exactParams: boolean\n) => Expectation;\n\nexport class ExpectationBuilderWithFactory implements ExpectationBuilder {\n private args: unknown[] | undefined;\n\n private property: Property | undefined;\n\n constructor(\n private createExpectation: ExpectationFactory,\n private concreteMatcher: ConcreteMatcher,\n private exactParams: boolean\n ) {}\n\n setProperty(value: Property) {\n if (this.property) {\n throw new UnfinishedExpectation(this.property, this.args);\n }\n\n this.property = value;\n }\n\n setArgs(value: unknown[] | undefined) {\n this.args = value;\n }\n\n finish(returnValue: ReturnValue): Expectation {\n if (!this.property) {\n throw new MissingWhen();\n }\n\n const expectation = this.createExpectation(\n this.property,\n this.args,\n returnValue,\n this.concreteMatcher,\n this.exactParams\n );\n\n this.property = undefined;\n this.args = undefined;\n\n return expectation;\n }\n}\n","import { isEqual, isObjectLike, isUndefined, omitBy } from 'lodash';\nimport { printValue } from '../print';\nimport type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\nconst removeUndefined = (object: any): any => {\n if (Array.isArray(object)) {\n return object.map((x) => removeUndefined(x));\n }\n\n if (!isObjectLike(object)) {\n return object;\n }\n\n return omitBy(object, isUndefined);\n};\n\n/**\n * Compare values using deep equality.\n *\n * @param expected\n * @param strict By default, this matcher will treat a missing key in an object\n * and a key with the value `undefined` as not equal. It will also consider\n * non `Object` instances with different constructors as not equal. Setting\n * this to `false` will consider the objects in both cases as equal.\n *\n * @see {@link It.isPartial} or {@link It.isArray} if you want to nest matchers.\n * @see {@link It.is} if you want to use strict equality.\n */\nexport const deepEquals = <T>(\n expected: T,\n {\n strict = true,\n }: {\n strict?: boolean;\n } = {}\n): TypeMatcher<T> =>\n matches(\n (actual) => {\n if (strict) {\n return isEqual(actual, expected);\n }\n\n return isEqual(removeUndefined(actual), removeUndefined(expected));\n },\n {\n toString: () => printValue(expected),\n getDiff: (actual) => ({\n actual,\n expected,\n }),\n }\n );\n","import { deepEquals } from '../matchers/deep-equals';\nimport type { MockOptions } from './options';\nimport { UnexpectedProperty } from './options';\n\nexport type StrongMockDefaults = Required<MockOptions>;\n\nconst defaults: StrongMockDefaults = {\n concreteMatcher: deepEquals,\n unexpectedProperty: UnexpectedProperty.CALL_THROW,\n exactParams: false,\n};\n\nexport let currentDefaults: StrongMockDefaults = defaults;\n\n/**\n * Override strong-mock's defaults.\n *\n * @param newDefaults These will be applied to the library defaults. Multiple\n * calls don't stack e.g. calling this with `{}` will clear any previously\n * applied defaults.\n */\nexport const setDefaults = (newDefaults: MockOptions): void => {\n currentDefaults = {\n ...defaults,\n ...newDefaults,\n };\n};\n","import { NotAMock } from '../errors/api';\nimport type { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport type { ExpectationBuilder } from '../when/expectation-builder';\nimport type { StrongMockDefaults } from './defaults';\nimport type { Mock } from './mock';\n\n/**\n * Since `when` doesn't receive the mock subject (because we can't make it\n * consistently return it from `mock()`, `mock.foo` and `mock.bar()`) we need\n * to store a global state for the currently active mock.\n *\n * We also want to throw in the following case:\n *\n * ```\n * when(() => mock()) // forgot returns here\n * when(() => mock()) // should throw\n * ```\n *\n * For that reason we can't just store the currently active mock, but also\n * whether we finished the expectation or not.\n */\nlet activeMock: Mock<any> | undefined;\n\nexport const setActiveMock = (mock: Mock<any>) => {\n activeMock = mock;\n};\n\nexport const clearActiveMock = () => {\n activeMock = undefined;\n};\n\nexport const getActiveMock = (): Mock<any> => activeMock;\n\ntype MockState = {\n repository: ExpectationRepository;\n builder: ExpectationBuilder;\n options: StrongMockDefaults;\n};\n\n/**\n * Store a global map of all mocks created and their state.\n *\n * This is needed because we can't reliably pass the state between `when`\n * and `thenReturn`.\n */\nconst mockMap = new Map<Mock<any>, MockState>();\n\nexport const getMockState = (mock: Mock<any>): MockState => {\n if (mockMap.has(mock)) {\n return mockMap.get(mock)!;\n }\n\n throw new NotAMock();\n};\n\nexport const setMockState = (mock: Mock<any>, state: MockState): void => {\n mockMap.set(mock, state);\n};\n\nexport const getAllMocks = (): [Mock<any>, MockState][] =>\n Array.from(mockMap.entries());\n","import type { Mock } from './mock/mock';\n\nexport type Property = string | symbol;\n\nexport interface ProxyTraps {\n /**\n * Called when accessing any property on an object, except for\n * `.call`, `.apply` and `.bind`.\n */\n property: (property: Property) => unknown;\n\n /**\n * Called when calling a function.\n *\n * @example\n * ```\n * fn(...args)\n * ```\n *\n * @example\n * ```\n * fn.call(this, ...args)\n * ```\n *\n * @example\n * ```\n * fn.apply(this, [...args])\n * ```\n *\n * @example\n * ```\n * Reflect.apply(fn, this, [...args])\n * ```\n */\n apply: (args: unknown[]) => unknown;\n\n /**\n * Called when getting the proxy's own enumerable keys.\n *\n * @example\n * ```\n * Object.keys(proxy);\n * ```\n *\n * @example\n * ```\n * const foo = { ...proxy };\n * ```\n */\n ownKeys: () => Property[];\n}\n\nexport const createProxy = <T>(traps: ProxyTraps): Mock<T> =>\n // The Proxy target MUST be a function, otherwise we can't use the `apply` trap:\n // https://262.ecma-international.org/6.0/#sec-proxy-object-internal-methods-and-internal-slots-call-thisargument-argumentslist\n // eslint-disable-next-line no-empty-function,@typescript-eslint/no-empty-function\n new Proxy(/* istanbul ignore next */ () => {}, {\n get: (target, prop: string | symbol) => {\n if (prop === 'bind') {\n return (thisArg: unknown, ...args: unknown[]) =>\n (...moreArgs: unknown[]) =>\n traps.apply([...args, ...moreArgs]);\n }\n\n if (prop === 'apply') {\n return (thisArg: unknown, args: unknown[] | undefined) =>\n traps.apply(args || []);\n }\n\n if (prop === 'call') {\n return (thisArg: unknown, ...args: unknown[]) => traps.apply(args);\n }\n\n return traps.property(prop);\n },\n\n apply: (target, thisArg: unknown, args: unknown[]) => traps.apply(args),\n\n ownKeys: () => traps.ownKeys(),\n\n getOwnPropertyDescriptor(\n target: () => void,\n prop: string | symbol\n ): PropertyDescriptor | undefined {\n const keys = traps.ownKeys();\n\n if (keys.includes(prop)) {\n return {\n configurable: true,\n enumerable: true,\n };\n }\n\n return undefined;\n },\n }) as unknown as Mock<T>;\n","import { NestedWhen } from '../errors/api';\nimport { ApplyProp } from '../expectation/expectation';\nimport type { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport type { Property } from '../proxy';\nimport { createProxy } from '../proxy';\nimport type { ExpectationBuilder } from '../when/expectation-builder';\nimport { setActiveMock } from './map';\nimport type { Mock } from './mock';\nimport { Mode } from './mock';\n\nexport const createStub = <T>(\n repo: ExpectationRepository,\n builder: ExpectationBuilder,\n getCurrentMode: () => Mode\n): Mock<T> => {\n const stub = createProxy<T>({\n property: (property) => {\n if (getCurrentMode() === Mode.CALL) {\n return repo.get(property);\n }\n\n setActiveMock(stub);\n\n builder.setProperty(property);\n\n return createProxy({\n property: (childProp: Property) => {\n throw new NestedWhen(property, childProp);\n },\n apply: (args: unknown[]) => {\n builder.setArgs(args);\n },\n ownKeys: () => {\n throw new Error('Spreading during an expectation is not supported.');\n },\n });\n },\n apply: (args: unknown[]) => {\n if (getCurrentMode() === Mode.CALL) {\n return repo.apply(args);\n }\n\n setActiveMock(stub);\n\n builder.setProperty(ApplyProp);\n builder.setArgs(args);\n\n return undefined;\n },\n ownKeys: () => {\n if (getCurrentMode() === Mode.CALL) {\n return repo.getAllProperties();\n }\n\n throw new Error('Spreading during an expectation is not supported.');\n },\n });\n\n return stub;\n};\n","import { FlexibleRepository } from '../expectation/repository/flexible-repository';\nimport { StrongExpectation } from '../expectation/strong-expectation';\nimport { isMatcher } from '../matchers/matcher';\nimport type { ExpectationFactory } from '../when/expectation-builder';\nimport { ExpectationBuilderWithFactory } from '../when/expectation-builder';\nimport type { StrongMockDefaults } from './defaults';\nimport { currentDefaults } from './defaults';\nimport { setMockState } from './map';\nimport type { MockOptions } from './options';\nimport { createStub } from './stub';\n\nexport type Mock<T> = T;\n\nconst strongExpectationFactory: ExpectationFactory = (\n property,\n args,\n returnValue,\n concreteMatcher,\n exactParams\n) =>\n new StrongExpectation(\n property,\n // Wrap every non-matcher in the default matcher.\n args?.map((arg) => (isMatcher(arg) ? arg : concreteMatcher(arg))),\n returnValue,\n exactParams\n );\n\nexport enum Mode {\n EXPECT,\n CALL,\n}\n\nlet currentMode: Mode = Mode.CALL;\n\nexport const setMode = (mode: Mode) => {\n currentMode = mode;\n};\nconst getMode = () => currentMode;\n\n/**\n * Create a type safe mock.\n *\n * @see {@link when} Set expectations on the mock using `when`.\n *\n * @param options Configure the options for this specific mock, overriding any\n * defaults that were set with {@link setDefaults}.\n * @param options.unexpectedProperty Controls what happens when an unexpected\n * property is accessed.\n * @param options.concreteMatcher The matcher that will be used when one isn't\n * specified explicitly.\n * @param options.exactParams Controls whether the number of received arguments\n * has to match the expectation.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * fn() === 23;\n */\nexport const mock = <T>({\n unexpectedProperty,\n concreteMatcher,\n exactParams,\n}: MockOptions = {}): Mock<T> => {\n const options: StrongMockDefaults = {\n unexpectedProperty:\n unexpectedProperty ?? currentDefaults.unexpectedProperty,\n concreteMatcher: concreteMatcher ?? currentDefaults.concreteMatcher,\n exactParams: exactParams ?? currentDefaults.exactParams,\n };\n\n const repository = new FlexibleRepository(options.unexpectedProperty);\n\n const builder = new ExpectationBuilderWithFactory(\n strongExpectationFactory,\n options.concreteMatcher,\n options.exactParams\n );\n\n const stub = createStub<T>(repository, builder, getMode);\n\n setMockState(stub, {\n repository,\n builder,\n options,\n });\n\n return stub;\n};\n","import type { Expectation } from '../expectation/expectation';\n\nexport interface InvocationCount {\n /**\n * Expect a call to be made at least `min` times and at most `max` times.\n */\n between: (min: number, max: number) => void;\n\n /**\n * Expect a call to be made exactly `exact` times.\n *\n * Shortcut for `between(exact, exact)`.\n */\n times: (exact: number) => void;\n\n /**\n * Expect a call to be made any number of times, including never.\n *\n * Shortcut for `between(0, Infinity)`.\n */\n anyTimes: () => void;\n\n /**\n * Expect a call to be made at least `min` times.\n *\n * Shortcut for `between(min, Infinity)`.\n */\n atLeast: (min: number) => void;\n\n /**\n * Expect a call to be made at most `max` times.\n *\n * Shortcut for `between(0, max)`.\n */\n atMost: (max: number) => void;\n\n /**\n * Expect a call to be made exactly once.\n *\n * Shortcut for `times(1)`.\n */\n once: () => void;\n\n /**\n * Expect a call to be made exactly twice.\n *\n * Shortcut for `times(2)`.\n */\n twice: () => void;\n}\n\nexport const createInvocationCount = (\n expectation: Expectation\n): InvocationCount => ({\n between(min: number, max: number) {\n expectation.setInvocationCount(min, max);\n },\n\n /* istanbul ignore next */\n times(exact: number) {\n expectation.setInvocationCount(exact, exact);\n },\n\n /* istanbul ignore next */\n anyTimes(): void {\n expectation.setInvocationCount(0, 0);\n },\n\n /* istanbul ignore next */\n atLeast(min: number) {\n expectation.setInvocationCount(min, Infinity);\n },\n\n /* istanbul ignore next */\n atMost(max: number) {\n expectation.setInvocationCount(0, max);\n },\n\n /* istanbul ignore next */\n once() {\n expectation.setInvocationCount(1, 1);\n },\n\n /* istanbul ignore next */\n twice() {\n expectation.setInvocationCount(2, 2);\n },\n /* eslint-enable no-param-reassign, no-multi-assign */\n});\n","import type { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport type { ReturnValue } from '../expectation/repository/return-value';\nimport type { ExpectationBuilder } from '../when/expectation-builder';\nimport type { InvocationCount } from './invocation-count';\nimport { createInvocationCount } from './invocation-count';\n\nexport type PromiseStub<R, P> = {\n /**\n * Set the return value for the current call.\n *\n * @param value This needs to be of the same type as the value returned\n * by the call inside `when`.\n *\n * @example\n * when(() => fn()).thenReturn(Promise.resolve(23));\n *\n * @example\n * when(() => fn()).thenReturn(Promise.reject({ foo: 'bar' });\n */\n thenReturn: (value: P) => InvocationCount;\n\n /**\n * Set the return value for the current call.\n *\n * @param promiseValue This needs to be of the same type as the value inside\n * the promise returned by the `when` callback.\n *\n * @example\n * when(() => fn()).thenResolve('foo');\n */\n thenResolve: (promiseValue: R) => InvocationCount;\n\n /**\n * Make the current call reject with the given error.\n *\n * @param error An `Error` instance. You can pass just a message, and\n * it will be wrapped in an `Error` instance. If you want to reject with\n * a non error then use the {@link thenReturn} method.\n *\n * @example\n * when(() => fn()).thenReject(new Error('oops'));\n */\n thenReject: ((error: Error) => InvocationCount) &\n ((message: string) => InvocationCount) &\n (() => InvocationCount);\n};\n\nexport type NonPromiseStub<R> = {\n /**\n * Set the return value for the current call.\n *\n * @param returnValue This needs to be of the same type as the value returned\n * by the `when` callback.\n */\n thenReturn: (returnValue: R) => InvocationCount;\n\n /**\n * Make the current call throw the given error.\n *\n * @param error The error instance. If you want to throw a simple `Error`\n * you can pass just the message.\n */\n thenThrow: ((error: Error) => InvocationCount) &\n ((message: string) => InvocationCount) &\n (() => InvocationCount);\n};\n\nconst finishExpectation = (\n returnValue: ReturnValue,\n builder: ExpectationBuilder,\n repo: ExpectationRepository\n) => {\n const finishedExpectation = builder.finish(returnValue);\n\n repo.add(finishedExpectation);\n\n return createInvocationCount(finishedExpectation);\n};\n\nconst getError = (errorOrMessage: Error | string | undefined): Error => {\n if (typeof errorOrMessage === 'string') {\n return new Error(errorOrMessage);\n }\n\n if (errorOrMessage instanceof Error) {\n return errorOrMessage;\n }\n\n return new Error();\n};\n\nexport const createReturns = (\n builder: ExpectationBuilder,\n repository: ExpectationRepository\n) => ({\n thenReturn: (returnValue: any): InvocationCount =>\n finishExpectation(\n // This will handle both thenReturn(23) and thenReturn(Promise.resolve(3)).\n { value: returnValue, isError: false, isPromise: false },\n builder,\n repository\n ),\n thenThrow: (errorOrMessage?: Error | string): InvocationCount =>\n finishExpectation(\n { value: getError(errorOrMessage), isError: true, isPromise: false },\n builder,\n repository\n ),\n thenResolve: (promiseValue: any): InvocationCount =>\n finishExpectation(\n {\n value: promiseValue,\n isError: false,\n isPromise: true,\n },\n builder,\n repository\n ),\n\n thenReject: (errorOrMessage?: Error | string): InvocationCount =>\n finishExpectation(\n {\n value: getError(errorOrMessage),\n isError: true,\n isPromise: true,\n },\n builder,\n repository\n ),\n});\n","import { getActiveMock, getMockState } from '../mock/map';\nimport { Mode, setMode } from '../mock/mock';\nimport type { NonPromiseStub, PromiseStub } from '../return/returns';\nimport { createReturns } from '../return/returns';\n\ninterface When {\n <R>(expectation: () => Promise<R>): PromiseStub<R, Promise<R>>;\n <R>(expectation: () => R): NonPromiseStub<R>;\n}\n\n/**\n * Set an expectation on a mock.\n *\n * The expectation must be finished by setting a return value, even if the value\n * is `undefined`.\n *\n * If a call happens that was not expected then the mock will throw an error.\n * By default, the call is expected to only be made once. Use the invocation\n * count helpers to expect a call multiple times.\n *\n * @param expectation A callback to set the expectation on your mock. The\n * callback must return the value from the mock to properly infer types.\n *\n * @example\n * const fn = mock<() => void>();\n * when(() => fn()).thenReturn(undefined);\n *\n * @example\n * const fn = mock<() => number>();\n * when(() => fn()).thenReturn(42).atMost(3);\n *\n * @example\n * const fn = mock<(x: number) => Promise<number>();\n * when(() => fn(23)).thenResolve(42);\n */\nexport const when: When = <R>(expectation: () => R) => {\n setMode(Mode.EXPECT);\n expectation();\n setMode(Mode.CALL);\n\n const { builder, repository } = getMockState(getActiveMock());\n\n return createReturns(builder, repository);\n};\n","import { getAllMocks, getMockState } from '../mock/map';\nimport type { Mock } from '../mock/mock';\n\n/**\n * Remove any remaining expectations on the given mock.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * reset(fn);\n *\n * fn(); // throws\n */\nexport const reset = (mock: Mock<any>): void => {\n getMockState(mock).repository.clear();\n};\n\n/**\n * Reset all existing mocks.\n *\n * @see reset\n */\nexport const resetAll = (): void => {\n getAllMocks().forEach(([mock]) => {\n reset(mock);\n });\n};\n","import { DIM_COLOR } from 'jest-matcher-utils';\nimport type { Expectation } from '../expectation/expectation';\nimport type { CallMap } from '../expectation/repository/expectation-repository';\nimport { printCall, printRemainingExpectations } from '../print';\n\nexport class UnmetExpectations extends Error {\n constructor(expectations: Expectation[]) {\n super(\n DIM_COLOR(`There are unmet expectations:\n\n - ${expectations.map((e) => e.toString()).join('\\n - ')}`)\n );\n }\n}\n\n/**\n * Merge property accesses and method calls for the same property\n * into a single call.\n *\n * @example\n * mergeCalls({ getData: [{ arguments: undefined }, { arguments: [1, 2, 3] }] }\n * // returns { getData: [{ arguments: [1, 2, 3] } }\n */\nconst mergeCalls = (callMap: CallMap): CallMap =>\n new Map(\n Array.from(callMap.entries()).map(([property, calls]) => {\n const hasMethodCalls = calls.some((call) => call.arguments);\n const hasPropertyAccesses = calls.some((call) => !call.arguments);\n\n if (hasMethodCalls && hasPropertyAccesses) {\n return [property, calls.filter((call) => call.arguments)];\n }\n\n return [property, calls];\n })\n );\n\nexport class UnexpectedCalls extends Error {\n constructor(unexpectedCalls: CallMap, expectations: Expectation[]) {\n const printedCalls = Array.from(mergeCalls(unexpectedCalls).entries())\n .map(([property, calls]) =>\n calls.map((call) => printCall(property, call.arguments)).join('\\n - ')\n )\n .join('\\n - ');\n\n super(\n DIM_COLOR(`The following calls were unexpected:\n\n - ${printedCalls}\n\n${printRemainingExpectations(expectations)}`)\n );\n }\n}\n","import { UnexpectedCalls, UnmetExpectations } from '../errors/verify';\nimport type { ExpectationRepository } from '../expectation/repository/expectation-repository';\nimport { getAllMocks, getMockState } from '../mock/map';\nimport type { Mock } from '../mock/mock';\n\nexport const verifyRepo = (repository: ExpectationRepository) => {\n const unmetExpectations = repository.getUnmet();\n\n if (unmetExpectations.length) {\n throw new UnmetExpectations(unmetExpectations);\n }\n\n const callStats = repository.getCallStats();\n\n if (callStats.unexpected.size) {\n throw new UnexpectedCalls(callStats.unexpected, unmetExpectations);\n }\n};\n\n/**\n * Verify that all expectations on the given mock have been met.\n *\n * @throws Will throw if there are remaining expectations that were set\n * using `when` and that weren't met.\n *\n * @throws Will throw if any unexpected calls happened. Normally those\n * calls throw on their own, but the error might be caught by the code\n * being tested.\n *\n * @example\n * const fn = mock<() => number>();\n *\n * when(() => fn()).thenReturn(23);\n *\n * verify(fn); // throws\n */\nexport const verify = <T>(mock: Mock<T>): void => {\n const { repository } = getMockState(mock);\n\n verifyRepo(repository);\n};\n\n/**\n * Verify all existing mocks.\n *\n * @see verify\n */\nexport const verifyAll = (): void => {\n getAllMocks().forEach(([mock]) => {\n verify(mock);\n });\n};\n","import { printValue } from '../print';\nimport type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\n/**\n * Compare values using `Object.is`.\n *\n * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n *\n * @see It.deepEquals A matcher that uses deep equality.\n */\nexport const is = <T = unknown>(expected: T): TypeMatcher<T> =>\n matches((actual) => Object.is(actual, expected), {\n toString: () => `${printValue(expected)}`,\n getDiff: (actual) => ({ actual, expected }),\n });\n","import type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\n/**\n * Match any value, including `undefined` and `null`.\n *\n * @example\n * const fn = mock<(x: number, y: string) => number>();\n * when(() => fn(It.isAny(), It.isAny())).thenReturn(1);\n *\n * fn(23, 'foobar') === 1\n */\nexport const isAny = (): TypeMatcher<any> =>\n matches(() => true, {\n toString: () => 'Matcher<any>',\n });\n","import { printValue } from '../print';\nimport { deepEquals } from './deep-equals';\nimport type { TypeMatcher } from './matcher';\nimport { isMatcher, matches } from './matcher';\n\n/**\n * Match an array.\n *\n * Supports nested matchers.\n *\n * @param containing If given, the matched array has to contain ALL of these\n * elements in ANY order.\n *\n * @example\n * const fn = mock<(arr: number[]) => number>();\n * when(() => fn(It.isArray())).thenReturn(1);\n * when(() => fn(It.isArray([2, 3]))).thenReturn(2);\n *\n * fn({ length: 1, 0: 42 }) // throws\n * fn([]) === 1\n * fn([3, 2, 1]) === 2\n *\n * @example\n * It.isArray([It.isString({ containing: 'foobar' })])\n */\nexport const isArray = <T extends unknown[]>(containing?: T): TypeMatcher<T> =>\n matches(\n (actual) => {\n if (!Array.isArray(actual)) {\n return false;\n }\n\n if (!containing) {\n return true;\n }\n\n return containing.every(\n (x) =>\n actual.find((y) => {\n if (isMatcher(x)) {\n return x.matches(y);\n }\n\n return deepEquals(x).matches(y);\n }) !== undefined\n );\n },\n {\n toString: () =>\n containing ? `array(${printValue(containing)})` : 'array',\n getDiff: (actual) => {\n if (containing) {\n return {\n actual,\n expected: `Matcher<array>([${containing\n .map((value) => {\n if (isMatcher(value)) {\n return value.toString();\n }\n\n return value;\n })\n .join(', ')}])`,\n };\n }\n\n return {\n actual: `${printValue(actual)} (${typeof actual})`,\n expected: 'Matcher<array>',\n };\n },\n }\n );\n","import { printValue } from '../print';\nimport type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\n/**\n * Match any number.\n *\n * @example\n * const fn = mock<(x: number) => number>();\n * when(() => fn(It.isNumber())).returns(42);\n *\n * fn(20.5) === 42\n * fn(NaN) // throws\n */\nexport const isNumber = (): TypeMatcher<number> =>\n matches((actual) => typeof actual === 'number' && !Number.isNaN(actual), {\n toString: () => 'Matcher<number>',\n getDiff: (actual) => ({\n actual: `${printValue(actual)} (${typeof actual})`,\n expected: 'Matcher<number>',\n }),\n });\n","import { isObjectLike, isPlainObject as isPlainObjectLodash } from 'lodash';\nimport { printValue } from '../print';\nimport type { Property } from '../proxy';\nimport type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\ntype ObjectType = Record<Property, unknown>;\n\n/**\n * Matches any plain object e.g. object literals or objects created with `Object.create()`.\n *\n * Classes, arrays, maps, sets etc. are not considered plain objects.\n * You can use {@link isPartial} or {@link matches} to match those.\n *\n * @example\n * const fn = mock<({ foo: string }) => number>();\n * when(() => fn(It.isPlainObject())).thenReturn(42);\n *\n * fn({ foo: 'bar' }) // returns 42\n */\nexport const isPlainObject = <T extends ObjectType>(): TypeMatcher<T> =>\n matches((actual) => isPlainObjectLodash(actual), {\n toString: () => 'Matcher<object>',\n getDiff: (actual) => {\n const type = isObjectLike(actual) ? 'object-like' : typeof actual;\n\n return {\n actual: `${printValue(actual)} (${type})`,\n expected: 'Matcher<object>',\n };\n },\n });\n","import { cloneDeepWith, isPlainObject } from 'lodash';\nimport { printValue } from '../print';\nimport type { Property } from '../proxy';\nimport { deepEquals } from './deep-equals';\nimport { isArray } from './is-array';\nimport type { TypeMatcher } from './matcher';\nimport { isMatcher, matches } from './matcher';\n\ntype ObjectType = Record<Property, unknown>;\n\ntype DeepPartial<T> = T extends ObjectType\n ? { [K in keyof T]?: DeepPartial<T[K]> }\n : T;\n\nconst looksLikeObject = (value: unknown): value is ObjectType =>\n isPlainObject(value);\n\nconst getExpectedObjectDiff = (actual: unknown, expected: unknown): object =>\n Object.fromEntries(\n getKeys(expected).map((key) => {\n const expectedValue = getKey(expected, key);\n const actualValue = getKey(actual, key);\n\n if (isMatcher(expectedValue)) {\n return [key, expectedValue.getDiff(actualValue).expected];\n }\n\n if (looksLikeObject(expectedValue)) {\n return [key, getExpectedObjectDiff(actualValue, expectedValue)];\n }\n\n return [key, expectedValue];\n })\n );\n\nconst getActualObjectDiff = (actual: unknown, expected: unknown): unknown => {\n const actualKeys = getKeys(actual);\n const expectedKeys = new Set(getKeys(expected));\n const commonKeys = actualKeys.filter((key) => expectedKeys.has(key));\n\n if (!commonKeys.length) {\n // When we don't have any common keys we return the whole object\n // so the user can inspect what's in there.\n return actual;\n }\n\n return Object.fromEntries(\n commonKeys.map((key) => {\n const expectedValue = getKey(expected, key);\n const actualValue = getKey(actual, key);\n\n if (isMatcher(expectedValue)) {\n return [key, expectedValue.getDiff(actualValue).actual];\n }\n\n if (looksLikeObject(expectedValue)) {\n return [key, getActualObjectDiff(actualValue, expectedValue)];\n }\n\n return [key, actualValue];\n })\n );\n};\n\nconst getKeys = (value: unknown): Property[] => {\n if (typeof value === 'object' && value !== null) {\n return Reflect.ownKeys(value);\n }\n\n return [];\n};\n\nconst getKey = (value: unknown, key: Property): unknown =>\n // @ts-expect-error because we're fine with a runtime undefined value\n value?.[key];\n\nconst isMatch = (actual: unknown, expected: unknown): boolean => {\n const actualKeys = getKeys(actual);\n const expectedKeys = getKeys(expected);\n\n if (!isArray(expectedKeys).matches(actualKeys)) {\n return false;\n }\n\n return expectedKeys.every((key) => {\n const expectedValue = getKey(expected, key);\n const actualValue = getKey(actual, key);\n\n if (isMatcher(expectedValue)) {\n return expectedValue.matches(actualValue);\n }\n\n if (looksLikeObject(expectedValue)) {\n return isMatch(actualValue, expectedValue);\n }\n\n return deepEquals(expectedValue).matches(actualValue);\n });\n};\n\nconst deepPrintObject = (value: unknown) =>\n cloneDeepWith(value, (value) => {\n if (isMatcher(value)) {\n return value.toString();\n }\n\n return undefined;\n });\n\n/**\n * Check if an object recursively contains the expected properties,\n * i.e. the expected object is a subset of the received object.\n *\n * @param partial A subset of the expected object that will be recursively matched.\n * Supports nested matchers.\n * Concrete values will be compared with {@link deepEquals}.\n * Note that a `{}` partial will match ANY value including non-objects.\n * Use {@link isPlainObject} if you want to match any plain object.\n *\n * @example\n * const fn = mock<(pos: { x: number, y: number }) => number>();\n * when(() => fn(It.isPartial({ x: 23 }))).returns(42);\n *\n * fn({ x: 23, y: 200 }) // returns 42\n *\n * @example\n * It.isPartial({ foo: It.isString() })\n */\n// T is not constrained to ObjectType because of\n// https://github.com/microsoft/TypeScript/issues/57810,\n// but K is to avoid inferring non-object partials\nexport const isPartial = <T, K extends DeepPartial<T> & ObjectType>(\n partial: K\n): TypeMatcher<T> =>\n matches((actual) => isMatch(actual, partial), {\n toString: () => `Matcher<object>(${printValue(deepPrintObject(partial))})`,\n getDiff: (actual) => ({\n actual: getActualObjectDiff(actual, partial),\n expected: getExpectedObjectDiff(actual, partial),\n }),\n });\n","import type { TypeMatcher } from './matcher';\nimport { matches } from './matcher';\n\n/**\n * Match any string.\n *\n * @param matching An optional string or RegExp to match the string against.\n * If it's a string, a case-sensitive search will be performed.\n *\n * @example\n * const fn = mock<(x: string, y: string) => number>();\n * when(() => fn(It.isString(), It.isString('bar'))).returns(42);\n *\n * fn('foo', 'baz') // throws\n * fn('foo', 'bar') === 42\n */\nexport const isString = (matching?: string | RegExp): TypeMatcher<string> =>\n matches(\n (actual) => {\n if (typeof actual !== 'string') {\n return false;\n }\n\n if (!matching) {\n return true;\n }\n\n if (typeof matching === 'string') {\n return actual.indexOf(matching) !== -1;\n }\n\n return matching.test(actual);\n },\n {\n toString: () => {\n if (matching) {\n return `Matcher<string>(${matching})`;\n }\n\n return 'Matcher<string>';\n },\n getDiff: (actual) => {\n if (matching) {\n return {\n expected: `Matcher<string>(${matching})`,\n actual,\n };\n }\n\n return {\n expected: 'Matcher<string>',\n actual: `${actual} (${typeof actual})`,\n };\n },\n }\n );\n","import type { Matcher, TypeMatcher } from './matcher';\nimport { MATCHER_SYMBOL } from './matcher';\n\n/**\n * Matches anything and stores the received value.\n *\n * This should not be needed for most cases, but can be useful if you need\n * access to a complex argument outside the expectation e.g. to test a\n * callback.\n *\n * @param name If given, this name will be printed in error messages.\n *\n * @example\n * const fn = mock<(cb: (value: number) => number) => void>();\n * const matcher = It.willCapture();\n * when(() => fn(matcher)).thenReturn();\n *\n * fn(x => x + 1);\n * matcher.value?.(3) === 4\n */\nexport const willCapture = <T = unknown>(\n name?: string\n): TypeMatcher<T> & {\n value: T | undefined;\n} => {\n let capturedValue: T | undefined;\n\n const matcher: Matcher & {\n value: T | undefined;\n } = {\n [MATCHER_SYMBOL]: true,\n matches: (actual) => {\n capturedValue = actual;\n\n return true;\n },\n toString: () => (name ? `Capture(${name})` : 'Capture'),\n getDiff: (actual) => ({\n actual,\n expected: actual,\n }),\n get value(): T | undefined {\n return capturedValue;\n },\n };\n\n return matcher as any;\n};\n","/* istanbul ignore file */\nexport { deepEquals } from './deep-equals';\n\nexport { is } from './is';\n\nexport { isAny } from './is-any';\n\nexport { isArray } from './is-array';\n\nexport { isNumber } from './is-number';\n\nexport { isPlainObject } from './is-plain-object';\n\nexport { isPartial } from './is-partial';\n\nexport { isString } from './is-string';\n\nexport { matches } from './matcher';\n\nexport { willCapture } from './will-capture';\n"],"names":["ApplyProp","Symbol","MATCHER_SYMBOL","isMatcher","f","getMatcherDiffs","matchers","args","matcherDiffs","map","matcher","i","getDiff","actual","d","expected","matches","predicate","options","toString","printProperty","property","printValue","arg","stringify","printArgs","join","printCall","prettyProperty","prettyArgs","RECEIVED_COLOR","printReturns","isError","isPromise","value","min","max","thenPrefix","printWhen","EXPECTED_COLOR","printExpectation","returnValue","printRemainingExpectations","expectations","length","e","UnexpectedAccess","Error","constructor","DIM_COLOR","printArgsDiff","diff","printDiff","omitAnnotationLines","ansilessDiffLines","stripAnsi","split","relevantDiffLines","slice","lastLine","coloredDiffLines","line","first","charAt","printExpectationDiff","printDiffForAllExpectations","undefined","filter","x","UnexpectedCall","header","propertyExpectations","matcherResult","UnexpectedProperty","unboxReturnValue","Promise","reject","resolve","FlexibleRepository","unexpectedProperty","THROW","Map","expectedCallStats","unexpectedCallStats","apply","get","handlePropertyWithMatchingExpectations","recordExpected","propertyExpectation","find","expectation","countAndConsume","callExpectation","getValueForUnexpectedCall","handlePropertyWithNoExpectations","toStringTag","getValueForUnexpectedAccess","add","set","matchCount","clear","getAllProperties","Array","from","keys","getCallStats","unexpected","getUnmet","concat","values","calls","arguments","recordUnexpected","consumeExpectation","StrongExpectation","exactParams","matched","setInvocationCount","matchesArgs","isUnmet","received","every","UnfinishedExpectation","MissingWhen","NotAMock","NestedWhen","parentProp","childProp","snippet","ExpectationBuilderWithFactory","createExpectation","concreteMatcher","setProperty","setArgs","finish","removeUndefined","object","isArray","isObjectLike","omitBy","isUndefined","deepEquals","strict","isEqual","defaults","CALL_THROW","currentDefaults","setDefaults","newDefaults","activeMock","setActiveMock","mock","getActiveMock","mockMap","getMockState","has","setMockState","state","getAllMocks","entries","createProxy","traps","Proxy","target","prop","thisArg","moreArgs","ownKeys","getOwnPropertyDescriptor","includes","configurable","enumerable","createStub","repo","builder","getCurrentMode","stub","Mode","CALL","strongExpectationFactory","currentMode","setMode","mode","getMode","repository","createInvocationCount","between","times","exact","anyTimes","atLeast","Infinity","atMost","once","twice","finishExpectation","finishedExpectation","getError","errorOrMessage","createReturns","thenReturn","thenThrow","thenResolve","promiseValue","thenReject","when","EXPECT","reset","resetAll","forEach","UnmetExpectations","mergeCalls","callMap","hasMethodCalls","some","call","hasPropertyAccesses","UnexpectedCalls","unexpectedCalls","printedCalls","verifyRepo","unmetExpectations","callStats","size","verify","verifyAll","is","Object","isAny","containing","y","isNumber","Number","isNaN","isPlainObject","isPlainObjectLodash","type","looksLikeObject","getExpectedObjectDiff","fromEntries","getKeys","key","expectedValue","getKey","actualValue","getActualObjectDiff","actualKeys","expectedKeys","Set","commonKeys","Reflect","isMatch","deepPrintObject","cloneDeepWith","isPartial","partial","isString","matching","indexOf","test","willCapture","name","capturedValue"],"mappings":";;;;;;;;;AAgCA;;;AAGO,MAAMA,SAAS,GAAGC,MAAM,CAAC,OAAD,CAAxB;;ACnCA,MAAMC,cAAc,GAAGD,MAAM,CAAC,SAAD,CAA7B;AAkEP;;;;SAGgBE,UAAUC;AACxB,S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AO,IAAP;AACD,KANC;AAOFM,IAAAA,QAAQ,EAAE,MAAOkP,IAAI,cAAcA,OAAd,GAAwB,SAP3C;AAQFzP,IAAAA,OAAO,EAAGC,MAAD,KAAa;AACpBA,MAAAA,MADoB;AAEpBE,MAAAA,QAAQ,EAAEF;AAFU,KAAb,CARP;;AAYF,QAAIqB,KAAJ;AACE,aAAOoO,aAAP;AACD;;AAdC,GAFJ;AAmBA,SAAO5P,OAAP;AACD,CA3BM;;ACpBP;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -8,9 +8,9 @@ import type { TypeMatcher } from './matcher';
|
|
|
8
8
|
* non `Object` instances with different constructors as not equal. Setting
|
|
9
9
|
* this to `false` will consider the objects in both cases as equal.
|
|
10
10
|
*
|
|
11
|
-
* @see {@link It.
|
|
11
|
+
* @see {@link It.isPartial} or {@link It.isArray} if you want to nest matchers.
|
|
12
12
|
* @see {@link It.is} if you want to use strict equality.
|
|
13
13
|
*/
|
|
14
14
|
export declare const deepEquals: <T>(expected: T, { strict, }?: {
|
|
15
|
-
strict?: boolean
|
|
15
|
+
strict?: boolean;
|
|
16
16
|
}) => TypeMatcher<T>;
|
|
@@ -19,4 +19,4 @@ import type { TypeMatcher } from './matcher';
|
|
|
19
19
|
* @example
|
|
20
20
|
* It.isArray([It.isString({ containing: 'foobar' })])
|
|
21
21
|
*/
|
|
22
|
-
export declare const isArray: <T extends unknown[]>(containing?: T
|
|
22
|
+
export declare const isArray: <T extends unknown[]>(containing?: T) => TypeMatcher<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Property } from '../proxy';
|
|
2
|
+
import type { TypeMatcher } from './matcher';
|
|
3
|
+
type ObjectType = Record<Property, unknown>;
|
|
4
|
+
type DeepPartial<T> = T extends ObjectType ? {
|
|
5
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
6
|
+
} : T;
|
|
7
|
+
/**
|
|
8
|
+
* Check if an object recursively contains the expected properties,
|
|
9
|
+
* i.e. the expected object is a subset of the received object.
|
|
10
|
+
*
|
|
11
|
+
* @param partial A subset of the expected object that will be recursively matched.
|
|
12
|
+
* Supports nested matchers.
|
|
13
|
+
* Concrete values will be compared with {@link deepEquals}.
|
|
14
|
+
* Note that a `{}` partial will match ANY value including non-objects.
|
|
15
|
+
* Use {@link isPlainObject} if you want to match any plain object.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const fn = mock<(pos: { x: number, y: number }) => number>();
|
|
19
|
+
* when(() => fn(It.isPartial({ x: 23 }))).returns(42);
|
|
20
|
+
*
|
|
21
|
+
* fn({ x: 23, y: 200 }) // returns 42
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* It.isPartial({ foo: It.isString() })
|
|
25
|
+
*/
|
|
26
|
+
export declare const isPartial: <T, K extends DeepPartial<T> & ObjectType>(partial: K) => TypeMatcher<T>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Property } from '../proxy';
|
|
2
|
+
import type { TypeMatcher } from './matcher';
|
|
3
|
+
type ObjectType = Record<Property, unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Matches any plain object e.g. object literals or objects created with `Object.create()`.
|
|
6
|
+
*
|
|
7
|
+
* Classes, arrays, maps, sets etc. are not considered plain objects.
|
|
8
|
+
* You can use {@link isPartial} or {@link matches} to match those.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const fn = mock<({ foo: string }) => number>();
|
|
12
|
+
* when(() => fn(It.isPlainObject())).thenReturn(42);
|
|
13
|
+
*
|
|
14
|
+
* fn({ foo: 'bar' }) // returns 42
|
|
15
|
+
*/
|
|
16
|
+
export declare const isPlainObject: <T extends ObjectType>() => TypeMatcher<T>;
|
|
17
|
+
export {};
|
package/dist/matchers/it.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export { is } from './is';
|
|
|
3
3
|
export { isAny } from './is-any';
|
|
4
4
|
export { isArray } from './is-array';
|
|
5
5
|
export { isNumber } from './is-number';
|
|
6
|
-
export {
|
|
6
|
+
export { isPlainObject } from './is-plain-object';
|
|
7
|
+
export { isPartial } from './is-partial';
|
|
7
8
|
export { isString } from './is-string';
|
|
8
9
|
export { matches } from './matcher';
|
|
9
10
|
export { willCapture } from './will-capture';
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export declare const MATCHER_SYMBOL: unique symbol;
|
|
2
|
+
export type MatcherDiffer = (actual: any) => {
|
|
3
|
+
actual: any;
|
|
4
|
+
expected: any;
|
|
5
|
+
};
|
|
2
6
|
export type MatcherOptions = {
|
|
3
7
|
/**
|
|
4
8
|
* Will be called when printing the diff between an expectation and the
|
|
@@ -24,10 +28,7 @@ export type MatcherOptions = {
|
|
|
24
28
|
* // - 'never'
|
|
25
29
|
* // + 42
|
|
26
30
|
*/
|
|
27
|
-
getDiff:
|
|
28
|
-
actual: any;
|
|
29
|
-
expected: any;
|
|
30
|
-
};
|
|
31
|
+
getDiff: MatcherDiffer;
|
|
31
32
|
/**
|
|
32
33
|
* Will be called when printing arguments for an unexpected or unmet expectation.
|
|
33
34
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TypeMatcher } from './matcher';
|
|
2
2
|
/**
|
|
3
3
|
* Matches anything and stores the received value.
|
|
4
4
|
*
|
|
@@ -16,6 +16,6 @@ import type { Matcher, TypeMatcher } from './matcher';
|
|
|
16
16
|
* fn(x => x + 1);
|
|
17
17
|
* matcher.value?.(3) === 4
|
|
18
18
|
*/
|
|
19
|
-
export declare const willCapture: <T = unknown>(name?: string) => T &
|
|
19
|
+
export declare const willCapture: <T = unknown>(name?: string) => TypeMatcher<T> & {
|
|
20
20
|
value: T | undefined;
|
|
21
21
|
};
|
package/dist/mock/mock.d.ts
CHANGED
|
@@ -26,4 +26,4 @@ export declare const setMode: (mode: Mode) => void;
|
|
|
26
26
|
*
|
|
27
27
|
* fn() === 23;
|
|
28
28
|
*/
|
|
29
|
-
export declare const mock: <T>({ unexpectedProperty, concreteMatcher, exactParams, }?: MockOptions) => T
|
|
29
|
+
export declare const mock: <T>({ unexpectedProperty, concreteMatcher, exactParams, }?: MockOptions) => Mock<T>;
|
package/dist/mock/stub.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import type { ExpectationRepository } from '../expectation/repository/expectatio
|
|
|
2
2
|
import type { ExpectationBuilder } from '../when/expectation-builder';
|
|
3
3
|
import type { Mock } from './mock';
|
|
4
4
|
import { Mode } from './mock';
|
|
5
|
-
export declare const createStub: <T>(repo: ExpectationRepository, builder: ExpectationBuilder, getCurrentMode: () => Mode) => T
|
|
5
|
+
export declare const createStub: <T>(repo: ExpectationRepository, builder: ExpectationBuilder, getCurrentMode: () => Mode) => Mock<T>;
|
package/dist/proxy.d.ts
CHANGED
package/dist/verify/verify.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const verifyRepo: (repository: ExpectationRepository) => void;
|
|
|
18
18
|
*
|
|
19
19
|
* verify(fn); // throws
|
|
20
20
|
*/
|
|
21
|
-
export declare const verify: <T>(mock: T) => void;
|
|
21
|
+
export declare const verify: <T>(mock: Mock<T>) => void;
|
|
22
22
|
/**
|
|
23
23
|
* Verify all existing mocks.
|
|
24
24
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strong-mock",
|
|
3
|
-
"version": "9.0.0-beta.
|
|
3
|
+
"version": "9.0.0-beta.2",
|
|
4
4
|
"description": "Type safe mocking library for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tdd",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"@tdd-buffet/jest-config": "~6.0.0",
|
|
35
35
|
"@tdd-buffet/tsconfig": "~1.0.5",
|
|
36
36
|
"@types/jest": "~29.5.0",
|
|
37
|
-
"@types/node": "~
|
|
38
|
-
"@types/lodash": "~4.
|
|
37
|
+
"@types/node": "~20.12.0",
|
|
38
|
+
"@types/lodash": "~4.17.0",
|
|
39
39
|
"doctoc": "~2.2.0",
|
|
40
|
-
"eslint": "~8.
|
|
40
|
+
"eslint": "~8.57.0",
|
|
41
41
|
"jest": "~29.7.0",
|
|
42
42
|
"microbundle": "~0.15.0",
|
|
43
43
|
"standard-version": "~9.5.0",
|
|
44
44
|
"strong-mock": "~6.0.0",
|
|
45
45
|
"tslib": "~2.6.0",
|
|
46
|
-
"typescript": "~5.
|
|
46
|
+
"typescript": "~5.4.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"docs": "doctoc --title '**Table of Contents**' README.md",
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Property } from '../proxy';
|
|
2
|
-
import type { TypeMatcher } from './matcher';
|
|
3
|
-
type ObjectType = Record<Property, unknown>;
|
|
4
|
-
type DeepPartial<T> = T extends ObjectType ? {
|
|
5
|
-
[K in keyof T]?: DeepPartial<T[K]>;
|
|
6
|
-
} : T;
|
|
7
|
-
/**
|
|
8
|
-
* Match any plain object.
|
|
9
|
-
*
|
|
10
|
-
* Object like values, e.g. classes and arrays, will not be matched.
|
|
11
|
-
*
|
|
12
|
-
* @param partial An optional subset of the expected object that will be
|
|
13
|
-
* recursively matched. Supports nested matchers. Values will be
|
|
14
|
-
* compared with {@link deepEquals}.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const fn = mock<(pos: { x: number, y: number }) => number>();
|
|
18
|
-
* when(() => fn(It.isObject({ x: 23 }))).returns(42);
|
|
19
|
-
*
|
|
20
|
-
* fn({ x: 100, y: 200 }) // throws
|
|
21
|
-
* fn({ x: 23, y: 200 }) // returns 42
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* It.isObject({ foo: It.isString() })
|
|
25
|
-
*/
|
|
26
|
-
export declare const isObject: <T extends ObjectType, K extends DeepPartial<T>>(partial?: K | undefined) => TypeMatcher<T>;
|
|
27
|
-
export {};
|