vitest-auto-spy 5.11.0 → 5.13.0
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/AGENTS.md +10 -0
- package/README.md +20 -3
- package/dist/angular-router.js +1 -1
- package/dist/angular.js +154 -86
- package/dist/bun-angular.js +9 -7
- package/dist/bun.js +4 -4
- package/dist/{chunk-BDJYPKLB.js → chunk-33NJHIS2.js} +51 -27
- package/dist/{chunk-JOI3BLCL.js → chunk-ADBB2HQG.js} +3 -3
- package/dist/{chunk-F334GPEI.js → chunk-BWT7U4V4.js} +2 -2
- package/dist/{chunk-NQNHA3R4.js → chunk-MUJTPXMJ.js} +68 -11
- package/dist/{chunk-HZPV3CHD.js → chunk-OS4PTU6D.js} +2 -16
- package/dist/{chunk-FNOXP6VT.js → chunk-PA4ZNLNZ.js} +1 -1
- package/dist/{chunk-HXH2QXK2.js → chunk-RPEYIZPL.js} +1 -1
- package/dist/{chunk-GZLFVXCY.js → chunk-ZU55UY2M.js} +1 -1
- package/dist/cli.js +42 -20
- package/dist/console.js +3 -3
- package/dist/dom-stubs.js +59 -25
- package/dist/index.js +142 -75
- package/dist/jasmine.js +6 -6
- package/dist/nestjs.js +7 -7
- package/dist/node.cjs +63 -20
- package/dist/node.js +4 -4
- package/dist/react.js +6 -6
- package/dist/rstest.js +5 -5
- package/dist/setup.js +6 -6
- package/dist/svelte.js +6 -6
- package/dist/vue.js +7 -7
- package/package.json +2 -2
- package/skills/vitest-auto-spy/SKILL.md +7 -0
package/AGENTS.md
CHANGED
|
@@ -771,6 +771,15 @@ Precedence, first one set wins: the double's `onUnstubbedCall` → the double's
|
|
|
771
771
|
and a `calledWith` configured after them is never consulted. After the last `mockReturnValueOnce`
|
|
772
772
|
the queue empties back onto the library dispatch and the next call **is** reported as unstubbed —
|
|
773
773
|
seed `mockReturnValue(...)` too when a `Once` sequence is meant to run out.
|
|
774
|
+
- **That pair is reported, in both orders.** `mockReturnValue` after a `calledWith` erases it;
|
|
775
|
+
`calledWith` after a `mockReturnValue` is dead on arrival. Neither fails on its own — the spec goes
|
|
776
|
+
green on a branch nobody configured — so the library says so as a misconfiguration (warn, or throw
|
|
777
|
+
under the `strict` preset). The whole family replaces: `mockImplementation`, `mockReturnValue`,
|
|
778
|
+
`mockReturnThis`, `mockThrow`, `mockResolvedValue`, `mockRejectedValue`. When both a fallback and a
|
|
779
|
+
per-argument value are wanted, the fallback goes in the spy's container — `returns:` where the
|
|
780
|
+
double is built, or `resolveWith` / `nextWith` / `failWith` — which a `calledWith` still wins over.
|
|
781
|
+
The report is this library's own spy engine's, so Vitest and Rstest have it; Bun, `node:test` and
|
|
782
|
+
`setSpyEngine('runner')` do not. The `Once` family is never reported.
|
|
774
783
|
- **A throw something swallowed still fails the test.** Under `setupAutoSpy({ strict: true })` every
|
|
775
784
|
strict throw is recorded, and one that a `try`/`catch` in the code under test or an RxJS error with
|
|
776
785
|
no handler (its rethrow waits on a fake clock) kept from the test fails it after the test
|
|
@@ -3418,6 +3427,7 @@ packages, which a subpath export can never be.
|
|
|
3418
3427
|
| `NG0303` / `NG0304` / nothing at all, from a directive spec | the host is `standalone: false`, or the module is in the TestBed | `createDirectiveHost({ template, scope: [Module] })` (§13) |
|
|
3419
3428
|
| `setInputs: … declares no input named …` | the key is not an input of that component — a typo, an input renamed since, or one of its own fields | set the names the message lists; a signal the component owns is moved through the signal (§13) |
|
|
3420
3429
|
| `setInputs: X carries no ɵcmp, so there are no inputs to set` | the fixture's `componentType` is not a compiled `@Component` — a `@Directive` or `@Pipe` class, or one Angular never compiled (a barrel import that resolved to `undefined`) | pass a component fixture; a directive takes its inputs through the host element that applies it (`createDirectiveHost`), and for `undefined` import the class from its own file (§13) |
|
|
3430
|
+
| `TypeError: dependencies is not a function`, from `renderShallow({ keepTemplate: true })` | the compiled `ɵcmp.dependencies` is the flat array AOT emits when no cycle forced a factory, and the trim called it | upgrade — all three shapes (array, factory, `null`) are read; nothing to change in the spec |
|
|
3421
3431
|
| `TS2540: Cannot assign to 'X' because it is a read-only property` | a `readonly` field of an object under test | `mockValueProp(obj, 'X', value)` — on a class **getter**, `mockReadonlyProp` |
|
|
3422
3432
|
| `TypeError: Cannot read properties of undefined (reading 'mockReturnValue')` | the member is an **instance field**, not on the prototype — `Router.currentNavigation` since Angular 20 | `provideAutoSpy(Router, { instanceMethodsToSpyOn: ['currentNavigation'] })` (§5) |
|
|
3423
3433
|
| `throwWith` reaching the success branch first, with the previous test's value | the spy's `ReplaySubject(1)` outlived the test that filled it | upgrade; and `resetAutoSpy(spy)` in `beforeEach` when the TestBed is built in `beforeAll` |
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ faster at suite scale ([benchmarks](#benchmarks)) — and for
|
|
|
23
23
|
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
24
24
|
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
25
25
|
[](https://github.com/ASDAlexey/vitest-auto-spy/actions/workflows/ci.yml)
|
|
26
|
-
[](#install)
|
|
27
27
|
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
28
28
|
[](https://github.com/ASDAlexey/vitest-auto-spy/actions/workflows/ci.yml)
|
|
29
29
|
[](./LICENSE)
|
|
@@ -2091,6 +2091,17 @@ myService.getName.mustBeCalledWith(1).mockReturnValue('Fake Name');
|
|
|
2091
2091
|
expect(() => myService.getName(2)).toThrow();
|
|
2092
2092
|
```
|
|
2093
2093
|
|
|
2094
|
+
**The first line and the second do not layer.** `mockReturnValue` and its family
|
|
2095
|
+
(`mockImplementation`, `mockResolvedValue`, `mockRejectedValue`, `mockThrow`, `mockReturnThis`)
|
|
2096
|
+
install an implementation on the host mock, and the dispatch that reads a `calledWith` chain **is**
|
|
2097
|
+
the implementation they replace — so the one written later wins outright and the other decides
|
|
2098
|
+
nothing, in either order, without failing. Both orders are now reported as a misconfiguration (a
|
|
2099
|
+
warning, a throw under the `strict` preset). Where both are wanted, the fallback goes in the spy's
|
|
2100
|
+
own container, which a chain still wins over: the `returns` option where the double is built, or
|
|
2101
|
+
`resolveWith` / `nextWith` / `failWith`. The report comes from this library's own spy engine — so
|
|
2102
|
+
Vitest and Rstest, not Bun or `node:test`, and not under `setSpyEngine('runner')` — and the `Once`
|
|
2103
|
+
family is never reported, because its queue drains back onto the dispatch.
|
|
2104
|
+
|
|
2094
2105
|
The failure prints both sides, because the diagnosis is the comparison rather than either half of
|
|
2095
2106
|
it — and every configured call when there is more than one, matchers included, so a config that
|
|
2096
2107
|
never matched is visible instead of inferred:
|
|
@@ -2371,8 +2382,14 @@ which shallow rendering touches.
|
|
|
2371
2382
|
override keeps the component's own `imports` minus the child _components_, so the template renders
|
|
2372
2383
|
with its own pipes and directives working while every child component in it resolves to nothing
|
|
2373
2384
|
under `NO_ERRORS_SCHEMA`. (Before 5.4.0 the whole scope was dropped, which made a pipe in a kept
|
|
2374
|
-
template throw `NG0302` and an attribute directive silently never apply.)
|
|
2375
|
-
|
|
2385
|
+
template throw `NG0302` and an attribute directive silently never apply.) Those imports are read off
|
|
2386
|
+
`ɵcmp`, where the compiler leaves them in one of three shapes — the flat array, a factory returning
|
|
2387
|
+
it, or `null` for a component that imports nothing — and which one is not decided by JIT against
|
|
2388
|
+
AOT: JIT always emits the factory, AOT emits the array unless a cycle between two components forces
|
|
2389
|
+
it to defer the read. All three are handled; calling the array unconditionally was a
|
|
2390
|
+
`TypeError: dependencies is not a function` on an AOT-compiled component with no cycle in its
|
|
2391
|
+
imports. A child re-exported by an imported `NgModule` still renders — the module is kept whole.
|
|
2392
|
+
Reach for it when the spec reads
|
|
2376
2393
|
something the template creates, and keep `keepChildren` for the handful of children it genuinely
|
|
2377
2394
|
needs resolvable. Full write-up:
|
|
2378
2395
|
[Performance](https://asdalexey.github.io/vitest-auto-spy/core/performance#_2-rendering-the-child-subtree).
|
package/dist/angular-router.js
CHANGED
package/dist/angular.js
CHANGED
|
@@ -74,6 +74,46 @@ function attachHelpers(target, helpers) {
|
|
|
74
74
|
return target;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// src/lib/spy-mark.ts
|
|
78
|
+
var AUTO_SPY_MARK = /* @__PURE__ */ Symbol.for("vitest-auto-spy.mock");
|
|
79
|
+
var DEEP_CHILDREN = /* @__PURE__ */ Symbol.for("vitest-auto-spy.deepChildren");
|
|
80
|
+
function markAsMock(mock, mark = true) {
|
|
81
|
+
Object.defineProperty(mock, AUTO_SPY_MARK, { value: mark, enumerable: false, configurable: true });
|
|
82
|
+
}
|
|
83
|
+
function isMarkHooks(value) {
|
|
84
|
+
return typeof value === "object" && value !== null && "reset" in value && "clear" in value;
|
|
85
|
+
}
|
|
86
|
+
function hooksOf(mock) {
|
|
87
|
+
const mark = Reflect.get(mock, AUTO_SPY_MARK);
|
|
88
|
+
return isMarkHooks(mark) ? mark : void 0;
|
|
89
|
+
}
|
|
90
|
+
function isAutoSpyLike(value) {
|
|
91
|
+
if (typeof value !== "object" || value === null) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (AUTO_SPY_MARK in value) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
const accessorSpies = Reflect.get(value, "accessorSpies");
|
|
98
|
+
return typeof accessorSpies === "object" && accessorSpies !== null;
|
|
99
|
+
}
|
|
100
|
+
function isMarkedMock(value) {
|
|
101
|
+
return typeof value === "function" && AUTO_SPY_MARK in value;
|
|
102
|
+
}
|
|
103
|
+
function readDeepChildren(value) {
|
|
104
|
+
const children = Reflect.get(value, DEEP_CHILDREN);
|
|
105
|
+
if (!(children instanceof Map)) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
return [...children.values()].filter(isMarkedMock);
|
|
109
|
+
}
|
|
110
|
+
function runConfigReset(mock) {
|
|
111
|
+
hooksOf(mock)?.reset();
|
|
112
|
+
}
|
|
113
|
+
function runClearHook(mock) {
|
|
114
|
+
hooksOf(mock)?.clear();
|
|
115
|
+
}
|
|
116
|
+
|
|
77
117
|
// src/lib/spy-probe.ts
|
|
78
118
|
var FAST_SPY_BRAND = /* @__PURE__ */ Symbol.for("vitest-auto-spy.fastSpy");
|
|
79
119
|
function isFastSpy(value) {
|
|
@@ -274,8 +314,12 @@ definePrototypeMember("getMockImplementation", function getMockImplementation()
|
|
|
274
314
|
const config = configOf(self(this));
|
|
275
315
|
return config.onceImplementations[0] ?? config.implementation;
|
|
276
316
|
});
|
|
317
|
+
function replaceImplementation(spy, implementation, via) {
|
|
318
|
+
hooksOf(spy)?.implementationReplaced?.(implementation, via);
|
|
319
|
+
configOf(spy).implementation = implementation;
|
|
320
|
+
}
|
|
277
321
|
definePrototypeMember("mockImplementation", function mockImplementation(implementation) {
|
|
278
|
-
|
|
322
|
+
replaceImplementation(self(this), implementation, "mockImplementation");
|
|
279
323
|
return this;
|
|
280
324
|
});
|
|
281
325
|
definePrototypeMember("mockImplementationOnce", function mockImplementationOnce(implementation) {
|
|
@@ -307,18 +351,26 @@ definePrototypeMember(
|
|
|
307
351
|
}
|
|
308
352
|
);
|
|
309
353
|
definePrototypeMember("mockReturnThis", function mockReturnThis() {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
354
|
+
replaceImplementation(
|
|
355
|
+
self(this),
|
|
356
|
+
function returnThis() {
|
|
357
|
+
return this;
|
|
358
|
+
},
|
|
359
|
+
"mockReturnThis"
|
|
360
|
+
);
|
|
313
361
|
return this;
|
|
314
362
|
});
|
|
315
363
|
definePrototypeMember("mockReturnValue", function mockReturnValue(value) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
364
|
+
replaceImplementation(
|
|
365
|
+
self(this),
|
|
366
|
+
function returnValue() {
|
|
367
|
+
if (new.target) {
|
|
368
|
+
throwConstructorError("mockReturnValue");
|
|
369
|
+
}
|
|
370
|
+
return value;
|
|
371
|
+
},
|
|
372
|
+
"mockReturnValue"
|
|
373
|
+
);
|
|
322
374
|
return this;
|
|
323
375
|
});
|
|
324
376
|
definePrototypeMember("mockReturnValueOnce", function mockReturnValueOnce(value) {
|
|
@@ -331,9 +383,13 @@ definePrototypeMember("mockReturnValueOnce", function mockReturnValueOnce(value)
|
|
|
331
383
|
return this;
|
|
332
384
|
});
|
|
333
385
|
definePrototypeMember("mockThrow", function mockThrow(value) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
386
|
+
replaceImplementation(
|
|
387
|
+
self(this),
|
|
388
|
+
function throwValue() {
|
|
389
|
+
throw value;
|
|
390
|
+
},
|
|
391
|
+
"mockThrow"
|
|
392
|
+
);
|
|
337
393
|
return this;
|
|
338
394
|
});
|
|
339
395
|
definePrototypeMember("mockThrowOnce", function mockThrowOnce(value) {
|
|
@@ -343,12 +399,16 @@ definePrototypeMember("mockThrowOnce", function mockThrowOnce(value) {
|
|
|
343
399
|
return this;
|
|
344
400
|
});
|
|
345
401
|
definePrototypeMember("mockResolvedValue", function mockResolvedValue(value) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
402
|
+
replaceImplementation(
|
|
403
|
+
self(this),
|
|
404
|
+
function resolvedValue() {
|
|
405
|
+
if (new.target) {
|
|
406
|
+
throwConstructorError("mockResolvedValue");
|
|
407
|
+
}
|
|
408
|
+
return Promise.resolve(value);
|
|
409
|
+
},
|
|
410
|
+
"mockResolvedValue"
|
|
411
|
+
);
|
|
352
412
|
return this;
|
|
353
413
|
});
|
|
354
414
|
definePrototypeMember("mockResolvedValueOnce", function mockResolvedValueOnce(value) {
|
|
@@ -361,12 +421,16 @@ definePrototypeMember("mockResolvedValueOnce", function mockResolvedValueOnce(va
|
|
|
361
421
|
return this;
|
|
362
422
|
});
|
|
363
423
|
definePrototypeMember("mockRejectedValue", function mockRejectedValue(value) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
424
|
+
replaceImplementation(
|
|
425
|
+
self(this),
|
|
426
|
+
function rejectedValue() {
|
|
427
|
+
if (new.target) {
|
|
428
|
+
throwConstructorError("mockRejectedValue");
|
|
429
|
+
}
|
|
430
|
+
return Promise.reject(value);
|
|
431
|
+
},
|
|
432
|
+
"mockRejectedValue"
|
|
433
|
+
);
|
|
370
434
|
return this;
|
|
371
435
|
});
|
|
372
436
|
definePrototypeMember("mockRejectedValueOnce", function mockRejectedValueOnce(value) {
|
|
@@ -1067,6 +1131,17 @@ Actual: ${actualCall(functionName, actualArgs)}`;
|
|
|
1067
1131
|
})
|
|
1068
1132
|
};
|
|
1069
1133
|
|
|
1134
|
+
// src/lib/misconfiguration.ts
|
|
1135
|
+
function misconfigurationThrows() {
|
|
1136
|
+
return globalThis.__vitestAutoSpyMisconfiguration__ === "throw";
|
|
1137
|
+
}
|
|
1138
|
+
function reportMisconfiguration(message) {
|
|
1139
|
+
if (misconfigurationThrows()) {
|
|
1140
|
+
throw new Error(message);
|
|
1141
|
+
}
|
|
1142
|
+
console.warn(message);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1070
1145
|
// src/lib/promise-spy.ts
|
|
1071
1146
|
function toResolvedPerCallValues(valueConfigsPerCall) {
|
|
1072
1147
|
return valueConfigsPerCall.map(
|
|
@@ -1147,46 +1222,6 @@ function installSettledResultsPolyfill(mockFn) {
|
|
|
1147
1222
|
};
|
|
1148
1223
|
}
|
|
1149
1224
|
|
|
1150
|
-
// src/lib/spy-mark.ts
|
|
1151
|
-
var AUTO_SPY_MARK = /* @__PURE__ */ Symbol.for("vitest-auto-spy.mock");
|
|
1152
|
-
var DEEP_CHILDREN = /* @__PURE__ */ Symbol.for("vitest-auto-spy.deepChildren");
|
|
1153
|
-
function markAsMock(mock, mark = true) {
|
|
1154
|
-
Object.defineProperty(mock, AUTO_SPY_MARK, { value: mark, enumerable: false, configurable: true });
|
|
1155
|
-
}
|
|
1156
|
-
function isMarkHooks(value) {
|
|
1157
|
-
return typeof value === "object" && value !== null && "reset" in value && "clear" in value;
|
|
1158
|
-
}
|
|
1159
|
-
function hooksOf(mock) {
|
|
1160
|
-
const mark = Reflect.get(mock, AUTO_SPY_MARK);
|
|
1161
|
-
return isMarkHooks(mark) ? mark : void 0;
|
|
1162
|
-
}
|
|
1163
|
-
function isAutoSpyLike(value) {
|
|
1164
|
-
if (typeof value !== "object" || value === null) {
|
|
1165
|
-
return false;
|
|
1166
|
-
}
|
|
1167
|
-
if (AUTO_SPY_MARK in value) {
|
|
1168
|
-
return true;
|
|
1169
|
-
}
|
|
1170
|
-
const accessorSpies = Reflect.get(value, "accessorSpies");
|
|
1171
|
-
return typeof accessorSpies === "object" && accessorSpies !== null;
|
|
1172
|
-
}
|
|
1173
|
-
function isMarkedMock(value) {
|
|
1174
|
-
return typeof value === "function" && AUTO_SPY_MARK in value;
|
|
1175
|
-
}
|
|
1176
|
-
function readDeepChildren(value) {
|
|
1177
|
-
const children = Reflect.get(value, DEEP_CHILDREN);
|
|
1178
|
-
if (!(children instanceof Map)) {
|
|
1179
|
-
return [];
|
|
1180
|
-
}
|
|
1181
|
-
return [...children.values()].filter(isMarkedMock);
|
|
1182
|
-
}
|
|
1183
|
-
function runConfigReset(mock) {
|
|
1184
|
-
hooksOf(mock)?.reset();
|
|
1185
|
-
}
|
|
1186
|
-
function runClearHook(mock) {
|
|
1187
|
-
hooksOf(mock)?.clear();
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
1225
|
// src/lib/function-spy.ts
|
|
1191
1226
|
function isReturnValueContainer(value) {
|
|
1192
1227
|
return typeof value === "object" && value !== null && "value" in value;
|
|
@@ -1299,6 +1334,24 @@ function returnTheCorrectFakeValue(state, actualArgs, functionName, unstubbed) {
|
|
|
1299
1334
|
}
|
|
1300
1335
|
return unwrapContainer(state.valueContainer);
|
|
1301
1336
|
}
|
|
1337
|
+
function configuredChain(state) {
|
|
1338
|
+
if (state.calledWith) {
|
|
1339
|
+
return "calledWith";
|
|
1340
|
+
}
|
|
1341
|
+
return state.mustBeCalledWith ? "mustBeCalledWith" : void 0;
|
|
1342
|
+
}
|
|
1343
|
+
function dispatchReplacedMessage(name, via, chain, order) {
|
|
1344
|
+
const what = order === "erased" ? `${via}() replaced the dispatch of '${name}' after ${chain}() was configured on it` : `${chain}() was configured on '${name}' after ${via}() had replaced its dispatch`;
|
|
1345
|
+
return withDocs(
|
|
1346
|
+
`[vitest-auto-spy] ${what}, so the ${chain}() decides nothing \u2014 every call answers what ${via}() installed. A fallback the ${chain}() still wins over goes in the spy's own container instead: the 'returns' option where the double is built, or resolveWith/nextWith/failWith.`,
|
|
1347
|
+
DOCS_LINKS.createSpyFromClass
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
function reportLateChain(internals, chain) {
|
|
1351
|
+
if (internals.replacedBy !== void 0) {
|
|
1352
|
+
reportMisconfiguration(dispatchReplacedMessage(internals.name, internals.replacedBy, chain, "late"));
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1302
1355
|
function addMethodsToCalledWith(calledWith, calledWithArgs) {
|
|
1303
1356
|
const setReturnValue = (value) => {
|
|
1304
1357
|
calledWith.argsToValuesMap.set(calledWithArgs, { value });
|
|
@@ -1325,14 +1378,37 @@ function ensureCalledWithObject(state, chain) {
|
|
|
1325
1378
|
return created;
|
|
1326
1379
|
}
|
|
1327
1380
|
var FunctionSpyInternals = class {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1381
|
+
constructor(state, valueContainer, host, dispatch, recorder, name) {
|
|
1382
|
+
/** Built on the first stream helper, not on every spy — see {@link ObservableSupport.streamForFunctionSpy}. */
|
|
1383
|
+
this.#observable = void 0;
|
|
1384
|
+
/** The member that last installed an implementation of the host's own over the dispatch, if any. */
|
|
1385
|
+
this.replacedBy = void 0;
|
|
1331
1386
|
this.state = state;
|
|
1332
1387
|
this.valueContainer = valueContainer;
|
|
1333
1388
|
this.host = host;
|
|
1334
1389
|
this.dispatch = dispatch;
|
|
1335
1390
|
this.recorder = recorder;
|
|
1391
|
+
this.name = name;
|
|
1392
|
+
}
|
|
1393
|
+
#observable;
|
|
1394
|
+
/**
|
|
1395
|
+
* A host implementation went in over the dispatch — reported when it silently disables a
|
|
1396
|
+
* `calledWith` chain this spy already carries, and remembered so that a chain configured
|
|
1397
|
+
* afterwards can say the same thing (see {@link SPY_HELPERS}).
|
|
1398
|
+
*
|
|
1399
|
+
* Re-installing the dispatch itself is the opposite move — `resetAutoSpy` and the jasmine
|
|
1400
|
+
* namespace both do it — so it clears the flag instead of raising one.
|
|
1401
|
+
*/
|
|
1402
|
+
implementationReplaced(implementation, via) {
|
|
1403
|
+
if (implementation === this.dispatch) {
|
|
1404
|
+
this.replacedBy = void 0;
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
this.replacedBy = via;
|
|
1408
|
+
const chain = configuredChain(this.state);
|
|
1409
|
+
if (chain !== void 0) {
|
|
1410
|
+
reportMisconfiguration(dispatchReplacedMessage(this.name, via, chain, "erased"));
|
|
1411
|
+
}
|
|
1336
1412
|
}
|
|
1337
1413
|
/**
|
|
1338
1414
|
* The rxjs layer's state for this spy, materialised on first use.
|
|
@@ -1361,6 +1437,7 @@ var FunctionSpyInternals = class {
|
|
|
1361
1437
|
delete valueContainer.valuesPerCalls;
|
|
1362
1438
|
this.#observable?.reset();
|
|
1363
1439
|
getMockAdapter().restoreImplementation(this.host, this.dispatch);
|
|
1440
|
+
this.replacedBy = void 0;
|
|
1364
1441
|
}
|
|
1365
1442
|
/** Empties the polyfilled `settledResults` on `clearAutoSpy` / `resetAutoSpy` (a no-op on Vitest, where the host clears its native array). */
|
|
1366
1443
|
clear() {
|
|
@@ -1402,13 +1479,14 @@ var SPY_HELPERS = /* @__PURE__ */ Object.assign(
|
|
|
1402
1479
|
valueContainer.valuesPerCalls = [];
|
|
1403
1480
|
},
|
|
1404
1481
|
calledWith(...calledWithArgs) {
|
|
1405
|
-
|
|
1482
|
+
const internals = internalsOf(this, "calledWith");
|
|
1483
|
+
reportLateChain(internals, "calledWith");
|
|
1484
|
+
return addMethodsToCalledWith(ensureCalledWithObject(internals.state, "calledWith"), calledWithArgs);
|
|
1406
1485
|
},
|
|
1407
1486
|
mustBeCalledWith(...calledWithArgs) {
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
);
|
|
1487
|
+
const internals = internalsOf(this, "mustBeCalledWith");
|
|
1488
|
+
reportLateChain(internals, "mustBeCalledWith");
|
|
1489
|
+
return addMethodsToCalledWith(ensureCalledWithObject(internals.state, "mustBeCalledWith"), calledWithArgs);
|
|
1412
1490
|
}
|
|
1413
1491
|
}
|
|
1414
1492
|
);
|
|
@@ -1423,7 +1501,7 @@ function createFunctionSpy(name, unstubbed) {
|
|
|
1423
1501
|
const functionSpy = getMockAdapter().createMockFn(dispatch, name);
|
|
1424
1502
|
const recorder = installSettledResultsPolyfill(functionSpy);
|
|
1425
1503
|
settledResultsRecorder = recorder.record;
|
|
1426
|
-
const internals = new FunctionSpyInternals(state, valueContainer, functionSpy, dispatch, recorder);
|
|
1504
|
+
const internals = new FunctionSpyInternals(state, valueContainer, functionSpy, dispatch, recorder, name);
|
|
1427
1505
|
const spy = attachHelpers(functionSpy, SPY_HELPERS);
|
|
1428
1506
|
getObservableSupport()?.addToFunctionSpy(spy);
|
|
1429
1507
|
getJasmineSupport()?.addToFunctionSpy(spy, {
|
|
@@ -1439,17 +1517,6 @@ function exposeAsSpy(spy) {
|
|
|
1439
1517
|
return spy;
|
|
1440
1518
|
}
|
|
1441
1519
|
|
|
1442
|
-
// src/lib/misconfiguration.ts
|
|
1443
|
-
function misconfigurationThrows() {
|
|
1444
|
-
return globalThis.__vitestAutoSpyMisconfiguration__ === "throw";
|
|
1445
|
-
}
|
|
1446
|
-
function reportMisconfiguration(message) {
|
|
1447
|
-
if (misconfigurationThrows()) {
|
|
1448
|
-
throw new Error(message);
|
|
1449
|
-
}
|
|
1450
|
-
console.warn(message);
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
1520
|
// src/lib/proxy-props.ts
|
|
1454
1521
|
function createProxyPropStore(seed) {
|
|
1455
1522
|
const store = { values: /* @__PURE__ */ new Map(), accessors: /* @__PURE__ */ new Map(), deleted: /* @__PURE__ */ new Set() };
|
|
@@ -3222,7 +3289,8 @@ function isStandalone3(definition2) {
|
|
|
3222
3289
|
}
|
|
3223
3290
|
function importsOf(definition2) {
|
|
3224
3291
|
const dependencies = Reflect.get(definition2, "dependencies");
|
|
3225
|
-
|
|
3292
|
+
const resolved = typeof dependencies === "function" ? dependencies() : dependencies;
|
|
3293
|
+
return Array.isArray(resolved) ? resolved : NOTHING;
|
|
3226
3294
|
}
|
|
3227
3295
|
function isChildComponent(dependency) {
|
|
3228
3296
|
return Reflect.get(dependency, "\u0275cmp") !== void 0;
|
package/dist/bun-angular.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { stable, flushEffects } from './chunk-M5BULP7X.js';
|
|
2
2
|
export { flushEffects, stable } from './chunk-M5BULP7X.js';
|
|
3
3
|
import './chunk-M6VMOOZ2.js';
|
|
4
|
-
export { asInstance, asInstances, asSpy, assertMocked, captureArg, createFixture, createFixtureFactory, createMock, createSpyClass, createSpyFromInstance, describeDuplicateCopies, expectCompletion, expectEmission, expectEmissions, expectError, expectNoEmission, flushEventLoop, flushEventLoopUntil, getPackageCopies, mockConstructor, mockDeep, moduleNamespace, narrow, restoreSpiedInstance, setEmissionTimeout, settleDynamicImport, stubConstructor, withOverrides } from './chunk-
|
|
4
|
+
export { asInstance, asInstances, asSpy, assertMocked, captureArg, createFixture, createFixtureFactory, createMock, createSpyClass, createSpyFromInstance, describeDuplicateCopies, expectCompletion, expectEmission, expectEmissions, expectError, expectNoEmission, flushEventLoop, flushEventLoopUntil, getPackageCopies, mockConstructor, mockDeep, moduleNamespace, narrow, restoreSpiedInstance, setEmissionTimeout, settleDynamicImport, stubConstructor, withOverrides } from './chunk-ADBB2HQG.js';
|
|
5
5
|
import { currentSpecFile, mockValueProp } from './chunk-N3T7KWWA.js';
|
|
6
6
|
export { countMockedProps, mockAccessorsProp, mockReadonlyProp, mockReadonlyPropGetter, mockValueProp, reportPropsOutsideHooks, restoreMockedProps } from './chunk-N3T7KWWA.js';
|
|
7
|
-
import { createSpyForToken } from './chunk-
|
|
8
|
-
import { createSpyFromClass } from './chunk-
|
|
9
|
-
export { autoMocked, clearAutoSpy, clearAutoSpyDefaults, createAutoMock, createSpyFromClass, registerAutoSpyDefaults, resetAutoSpy } from './chunk-
|
|
10
|
-
import
|
|
7
|
+
import { createSpyForToken } from './chunk-RPEYIZPL.js';
|
|
8
|
+
import { createSpyFromClass } from './chunk-BWT7U4V4.js';
|
|
9
|
+
export { autoMocked, clearAutoSpy, clearAutoSpyDefaults, createAutoMock, createSpyFromClass, registerAutoSpyDefaults, resetAutoSpy } from './chunk-BWT7U4V4.js';
|
|
10
|
+
import './chunk-OS4PTU6D.js';
|
|
11
11
|
import './chunk-DTZCPCMA.js';
|
|
12
12
|
import './chunk-PC3FAZT3.js';
|
|
13
|
-
|
|
13
|
+
import { misconfigurationThrows, reportMisconfiguration } from './chunk-MUJTPXMJ.js';
|
|
14
|
+
export { createFunctionSpy, errorHandler } from './chunk-MUJTPXMJ.js';
|
|
14
15
|
import { isAutoSpyLike } from './chunk-OTOCFH6B.js';
|
|
15
16
|
import { withDocs, DOCS_LINKS } from './chunk-Q477VHHF.js';
|
|
16
17
|
import '@angular/compiler';
|
|
@@ -310,7 +311,8 @@ function isStandalone(definition) {
|
|
|
310
311
|
}
|
|
311
312
|
function importsOf(definition) {
|
|
312
313
|
const dependencies = Reflect.get(definition, "dependencies");
|
|
313
|
-
|
|
314
|
+
const resolved = typeof dependencies === "function" ? dependencies() : dependencies;
|
|
315
|
+
return Array.isArray(resolved) ? resolved : NOTHING;
|
|
314
316
|
}
|
|
315
317
|
function isChildComponent(dependency) {
|
|
316
318
|
return Reflect.get(dependency, "\u0275cmp") !== void 0;
|
package/dist/bun.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import './chunk-M6VMOOZ2.js';
|
|
2
|
-
export { asInstance, asInstances, asSpy, assertMocked, captureArg, createFixture, createFixtureFactory, createMock, createSpyClass, createSpyFromInstance, describeDuplicateCopies, expectCompletion, expectEmission, expectEmissions, expectError, expectNoEmission, flushEventLoop, flushEventLoopUntil, getPackageCopies, mockConstructor, mockDeep, moduleNamespace, narrow, restoreSpiedInstance, setEmissionTimeout, settleDynamicImport, stubConstructor, withOverrides } from './chunk-
|
|
2
|
+
export { asInstance, asInstances, asSpy, assertMocked, captureArg, createFixture, createFixtureFactory, createMock, createSpyClass, createSpyFromInstance, describeDuplicateCopies, expectCompletion, expectEmission, expectEmissions, expectError, expectNoEmission, flushEventLoop, flushEventLoopUntil, getPackageCopies, mockConstructor, mockDeep, moduleNamespace, narrow, restoreSpiedInstance, setEmissionTimeout, settleDynamicImport, stubConstructor, withOverrides } from './chunk-ADBB2HQG.js';
|
|
3
3
|
export { countMockedProps, mockAccessorsProp, mockReadonlyProp, mockReadonlyPropGetter, mockValueProp, reportPropsOutsideHooks, restoreMockedProps } from './chunk-N3T7KWWA.js';
|
|
4
|
-
export { autoMocked, clearAutoSpy, clearAutoSpyDefaults, createAutoMock, createSpyFromClass, registerAutoSpyDefaults, resetAutoSpy } from './chunk-
|
|
5
|
-
import './chunk-
|
|
4
|
+
export { autoMocked, clearAutoSpy, clearAutoSpyDefaults, createAutoMock, createSpyFromClass, registerAutoSpyDefaults, resetAutoSpy } from './chunk-BWT7U4V4.js';
|
|
5
|
+
import './chunk-OS4PTU6D.js';
|
|
6
6
|
import './chunk-DTZCPCMA.js';
|
|
7
7
|
import './chunk-PC3FAZT3.js';
|
|
8
|
-
export { createFunctionSpy, errorHandler } from './chunk-
|
|
8
|
+
export { createFunctionSpy, errorHandler } from './chunk-MUJTPXMJ.js';
|
|
9
9
|
import './chunk-OTOCFH6B.js';
|
|
10
10
|
import './chunk-Q477VHHF.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DISPOSE } from './chunk-PC3FAZT3.js';
|
|
2
|
-
import { isFastSpy, FAST_SPY_BRAND, isThenable } from './chunk-
|
|
3
|
-
import { setSharedHelperSink } from './chunk-OTOCFH6B.js';
|
|
2
|
+
import { isFastSpy, FAST_SPY_BRAND, isThenable } from './chunk-MUJTPXMJ.js';
|
|
3
|
+
import { setSharedHelperSink, hooksOf } from './chunk-OTOCFH6B.js';
|
|
4
4
|
|
|
5
5
|
// src/lib/spy-engine.ts
|
|
6
6
|
var sharedEngine;
|
|
@@ -202,8 +202,12 @@ definePrototypeMember("getMockImplementation", function getMockImplementation()
|
|
|
202
202
|
const config = configOf(self(this));
|
|
203
203
|
return config.onceImplementations[0] ?? config.implementation;
|
|
204
204
|
});
|
|
205
|
+
function replaceImplementation(spy, implementation, via) {
|
|
206
|
+
hooksOf(spy)?.implementationReplaced?.(implementation, via);
|
|
207
|
+
configOf(spy).implementation = implementation;
|
|
208
|
+
}
|
|
205
209
|
definePrototypeMember("mockImplementation", function mockImplementation(implementation) {
|
|
206
|
-
|
|
210
|
+
replaceImplementation(self(this), implementation, "mockImplementation");
|
|
207
211
|
return this;
|
|
208
212
|
});
|
|
209
213
|
definePrototypeMember("mockImplementationOnce", function mockImplementationOnce(implementation) {
|
|
@@ -235,18 +239,26 @@ definePrototypeMember(
|
|
|
235
239
|
}
|
|
236
240
|
);
|
|
237
241
|
definePrototypeMember("mockReturnThis", function mockReturnThis() {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
replaceImplementation(
|
|
243
|
+
self(this),
|
|
244
|
+
function returnThis() {
|
|
245
|
+
return this;
|
|
246
|
+
},
|
|
247
|
+
"mockReturnThis"
|
|
248
|
+
);
|
|
241
249
|
return this;
|
|
242
250
|
});
|
|
243
251
|
definePrototypeMember("mockReturnValue", function mockReturnValue(value) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
252
|
+
replaceImplementation(
|
|
253
|
+
self(this),
|
|
254
|
+
function returnValue() {
|
|
255
|
+
if (new.target) {
|
|
256
|
+
throwConstructorError("mockReturnValue");
|
|
257
|
+
}
|
|
258
|
+
return value;
|
|
259
|
+
},
|
|
260
|
+
"mockReturnValue"
|
|
261
|
+
);
|
|
250
262
|
return this;
|
|
251
263
|
});
|
|
252
264
|
definePrototypeMember("mockReturnValueOnce", function mockReturnValueOnce(value) {
|
|
@@ -259,9 +271,13 @@ definePrototypeMember("mockReturnValueOnce", function mockReturnValueOnce(value)
|
|
|
259
271
|
return this;
|
|
260
272
|
});
|
|
261
273
|
definePrototypeMember("mockThrow", function mockThrow(value) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
274
|
+
replaceImplementation(
|
|
275
|
+
self(this),
|
|
276
|
+
function throwValue() {
|
|
277
|
+
throw value;
|
|
278
|
+
},
|
|
279
|
+
"mockThrow"
|
|
280
|
+
);
|
|
265
281
|
return this;
|
|
266
282
|
});
|
|
267
283
|
definePrototypeMember("mockThrowOnce", function mockThrowOnce(value) {
|
|
@@ -271,12 +287,16 @@ definePrototypeMember("mockThrowOnce", function mockThrowOnce(value) {
|
|
|
271
287
|
return this;
|
|
272
288
|
});
|
|
273
289
|
definePrototypeMember("mockResolvedValue", function mockResolvedValue(value) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
290
|
+
replaceImplementation(
|
|
291
|
+
self(this),
|
|
292
|
+
function resolvedValue() {
|
|
293
|
+
if (new.target) {
|
|
294
|
+
throwConstructorError("mockResolvedValue");
|
|
295
|
+
}
|
|
296
|
+
return Promise.resolve(value);
|
|
297
|
+
},
|
|
298
|
+
"mockResolvedValue"
|
|
299
|
+
);
|
|
280
300
|
return this;
|
|
281
301
|
});
|
|
282
302
|
definePrototypeMember("mockResolvedValueOnce", function mockResolvedValueOnce(value) {
|
|
@@ -289,12 +309,16 @@ definePrototypeMember("mockResolvedValueOnce", function mockResolvedValueOnce(va
|
|
|
289
309
|
return this;
|
|
290
310
|
});
|
|
291
311
|
definePrototypeMember("mockRejectedValue", function mockRejectedValue(value) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
312
|
+
replaceImplementation(
|
|
313
|
+
self(this),
|
|
314
|
+
function rejectedValue() {
|
|
315
|
+
if (new.target) {
|
|
316
|
+
throwConstructorError("mockRejectedValue");
|
|
317
|
+
}
|
|
318
|
+
return Promise.reject(value);
|
|
319
|
+
},
|
|
320
|
+
"mockRejectedValue"
|
|
321
|
+
);
|
|
298
322
|
return this;
|
|
299
323
|
});
|
|
300
324
|
definePrototypeMember("mockRejectedValueOnce", function mockRejectedValueOnce(value) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { mockValueProp, mockAccessorsProp } from './chunk-N3T7KWWA.js';
|
|
2
|
-
import { resolveConfiguration, mergeMethodNames, getCallableMemberNames, applyConfiguredReturns, createSpyFromClass, resolveAccessors, createAccessorsSpies, createProxyPropStore, storeWriteTraps, describeStoredProp, readStoredAccessor, NOT_STORED, disposeAutoSpy, isProtocolKey, isDeletedProp } from './chunk-
|
|
3
|
-
import { resolveReadGuard, createTrackedPropSpy } from './chunk-
|
|
2
|
+
import { resolveConfiguration, mergeMethodNames, getCallableMemberNames, applyConfiguredReturns, createSpyFromClass, resolveAccessors, createAccessorsSpies, createProxyPropStore, storeWriteTraps, describeStoredProp, readStoredAccessor, NOT_STORED, disposeAutoSpy, isProtocolKey, isDeletedProp } from './chunk-BWT7U4V4.js';
|
|
3
|
+
import { resolveReadGuard, createTrackedPropSpy } from './chunk-OS4PTU6D.js';
|
|
4
4
|
import { redefineFailure } from './chunk-DTZCPCMA.js';
|
|
5
5
|
import { DISPOSE } from './chunk-PC3FAZT3.js';
|
|
6
|
-
import { defineHelper, serializeValue, resolveUnstubbedGuard, createFunctionSpy } from './chunk-
|
|
6
|
+
import { defineHelper, serializeValue, resolveUnstubbedGuard, createFunctionSpy } from './chunk-MUJTPXMJ.js';
|
|
7
7
|
import { DEEP_CHILDREN } from './chunk-OTOCFH6B.js';
|
|
8
8
|
import { withDocs, DOCS_LINKS } from './chunk-Q477VHHF.js';
|
|
9
9
|
import { getMockAdapter, emissionTimeout } from './shared-state.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { resolveReadGuard, createTrackedPropSpy,
|
|
1
|
+
import { resolveReadGuard, createTrackedPropSpy, unconfiguredGetter } from './chunk-OS4PTU6D.js';
|
|
2
2
|
import { DISPOSE } from './chunk-PC3FAZT3.js';
|
|
3
|
-
import { resolveUnstubbedGuard, seedReturnValue, createFunctionSpy } from './chunk-
|
|
3
|
+
import { resolveUnstubbedGuard, reportMisconfiguration, seedReturnValue, createFunctionSpy } from './chunk-MUJTPXMJ.js';
|
|
4
4
|
import { runClearHook, runConfigReset, AUTO_SPY_MARK, markAsMock, isMarkedMock, readDeepChildren } from './chunk-OTOCFH6B.js';
|
|
5
5
|
import { withDocs, DOCS_LINKS } from './chunk-Q477VHHF.js';
|
|
6
6
|
import { getMockAdapter, getJasmineSupport } from './shared-state.js';
|