vitest-auto-spy 5.6.0 → 5.8.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.
Files changed (65) hide show
  1. package/AGENTS.md +228 -25
  2. package/README.md +258 -55
  3. package/dist/angular-http.js +2 -2
  4. package/dist/angular-router.d.ts +102 -0
  5. package/dist/angular-router.js +184 -0
  6. package/dist/angular.d.ts +119 -8
  7. package/dist/angular.js +328 -82
  8. package/dist/bun-angular.d.ts +6 -6
  9. package/dist/bun-angular.js +13 -13
  10. package/dist/bun.d.ts +6 -165
  11. package/dist/bun.js +8 -8
  12. package/dist/{chunk-C5EPUC3A.js → chunk-56WFZULJ.js} +14 -11
  13. package/dist/{chunk-X57WQSOC.js → chunk-5PJOEE3N.js} +1 -1
  14. package/dist/{chunk-B45HLBA4.js → chunk-5ROGATP4.js} +2 -0
  15. package/dist/{chunk-APSBHO3I.js → chunk-A7U5NBQK.js} +2 -2
  16. package/dist/{chunk-B4Z3CFDJ.js → chunk-B273FCFO.js} +1 -1
  17. package/dist/{chunk-4XY4DEM5.js → chunk-ENI3G4RS.js} +2 -2
  18. package/dist/{chunk-SWXAPWFW.js → chunk-JIG2WCRH.js} +2 -2
  19. package/dist/{chunk-PBLYL3Q7.js → chunk-KXV23662.js} +2 -2
  20. package/dist/chunk-NRVAJJKN.js +113 -0
  21. package/dist/{chunk-ALFMIDWW.js → chunk-OG6UKRFZ.js} +1 -1
  22. package/dist/{chunk-YL7EQKZU.js → chunk-PSUX3M3P.js} +1 -1
  23. package/dist/{chunk-AVVUXEEI.js → chunk-PXYOVG56.js} +42 -6
  24. package/dist/{chunk-GSWNTF5E.js → chunk-UEG2I3VY.js} +59 -33
  25. package/dist/cli.js +207 -189
  26. package/dist/console.d.ts +1 -1
  27. package/dist/console.js +5 -5
  28. package/dist/dom-stubs.d.ts +2 -1
  29. package/dist/dom-stubs.js +41 -1
  30. package/dist/eslint-plugin.cjs +391 -10
  31. package/dist/eslint-plugin.d.cts +22 -1
  32. package/dist/eslint-plugin.d.ts +22 -1
  33. package/dist/{expect-emission-C0xY_mYK.d.ts → expect-emission-BUdHCyYJ.d.ts} +140 -4
  34. package/dist/index.d.ts +5 -5
  35. package/dist/index.js +168 -62
  36. package/dist/jasmine-compat.d.ts +1 -1
  37. package/dist/jasmine.d.ts +2 -2
  38. package/dist/jasmine.js +8 -8
  39. package/dist/nestjs.d.ts +2 -2
  40. package/dist/nestjs.js +9 -9
  41. package/dist/node.cjs +182 -74
  42. package/dist/node.d.ts +5 -5
  43. package/dist/node.js +8 -8
  44. package/dist/package-identity-DDylC3ri.d.ts +88 -0
  45. package/dist/{prop-mock-DmM-rPcG.d.ts → prop-mock-sa1PC4xj.d.ts} +1 -1
  46. package/dist/react.d.ts +5 -5
  47. package/dist/react.js +9 -9
  48. package/dist/rstest.d.ts +5 -5
  49. package/dist/rstest.js +9 -9
  50. package/dist/rxjs.d.ts +2 -2
  51. package/dist/rxjs.js +11 -4
  52. package/dist/setup.d.ts +34 -61
  53. package/dist/setup.js +62 -31
  54. package/dist/svelte.d.ts +5 -5
  55. package/dist/svelte.js +9 -9
  56. package/dist/{track-injections-D4TuS8yk.d.ts → track-injections-D1KdfjXr.d.ts} +1 -1
  57. package/dist/{types-DTi4dIeN.d.ts → types-CrmNZKfd.d.ts} +64 -8
  58. package/dist/vue.d.ts +6 -6
  59. package/dist/vue.js +10 -10
  60. package/dist/web-storage-dwQ9E7Lm.d.ts +83 -0
  61. package/dist/{zoneless-DnjTTKlC.d.ts → zoneless-CBxpxspb.d.ts} +17 -4
  62. package/package.json +11 -1
  63. package/skills/vitest-auto-spy/SKILL.md +120 -85
  64. package/dist/chunk-RZRKEUE6.js +0 -15
  65. package/dist/package-identity-B1pqa-Sh.d.ts +0 -33
package/AGENTS.md CHANGED
@@ -57,9 +57,10 @@ Add-ons, orthogonal to the runner:
57
57
  | Observable spies | `import 'vitest-auto-spy/rxjs'` | `nextWith` & friends. **Side-effect import, once**, and in a file the `tsconfig` includes (§4) |
58
58
  | observer-spy shim | `vitest-auto-spy/observer-spy` | `subscribeSpyTo` — the `@hirez_io/observer-spy` surface (§20). Its own entry so `/rxjs` does not carry it |
59
59
  | Console spies | `vitest-auto-spy/console` | silent typed spies over the global `console` — `installConsoleSpies()` per test, `restoreConsole()` after |
60
- | DOM stubs | `vitest-auto-spy/dom-stubs` | `stubIntersectionObserver` / `stubResizeObserver` / `stubMutationObserver` / `stubObserver`, `stubMediaElement`, `stubAbortController`, `intersectionEntry` / `resizeEntry` / `mutationRecord`. **Moved off the root in 4.0.0** |
60
+ | DOM stubs | `vitest-auto-spy/dom-stubs` | `stubIntersectionObserver` / `stubResizeObserver` / `stubMutationObserver` / `stubObserver`, `stubMediaElement`, `stubAbortController`, `stubWebStorage` (§12), `intersectionEntry` / `resizeEntry` / `mutationRecord`. **Moved off the root in 4.0.0** |
61
61
  | Run diagnostics | `vitest-auto-spy/diagnostics` | `compareTestRuns`, `summarizeTestRun`, `formatTestRunComparison`, `diffByField`. **Moved off the root in 4.0.0** |
62
62
  | Angular HTTP | `vitest-auto-spy/angular-http` | `provideHttpTesting`, `expectRequest` — `httpResource()` / `HttpClient` (§13). Optional `@angular/common` peer, this entry only |
63
+ | Angular router | `vitest-auto-spy/angular-router` | `provideActivatedRoute`, `injectActivatedRoute` — an `ActivatedRoute` whose streams and snapshot share one record (§13). Optional `@angular/router` peer, this entry only |
63
64
  | Setup helpers | `vitest-auto-spy/setup` | `setupAutoSpy()`, `setupFakeTimers()` |
64
65
  | Zone patch | `import 'vitest-auto-spy/zone'` | `fakeAsync` / `waitForAsync` on Vitest (§14) |
65
66
  | jasmine compat | `vitest-auto-spy/jasmine` | `.and` / `.calls` / `.withArgs`, the `jasmine` namespace (§20) |
@@ -73,8 +74,8 @@ so the specifier moved to the root `rxjs` entry — which is where rxjs re-expor
73
74
  the floor moved with it. Any Angular project already satisfies it: Angular 16 through 22 all peer on
74
75
  `^6.5.3 || ^7.4.0`.
75
76
 
76
- The Angular entries need **Angular >= 20** — `@angular/core`, `@angular/common` and
77
- `@angular/platform-browser`, all optional peers on the same range. Below 20 the failure is a link
77
+ The Angular entries need **Angular >= 20** — `@angular/core`, `@angular/common`,
78
+ `@angular/platform-browser` and `@angular/router`, all optional peers on the same range. Below 20 the failure is a link
78
79
  error, not a missing helper: `/angular` imports `ɵSIGNAL` (Angular 18+) as a value on the first line
79
80
  of its bundle, so on 16 and 17 the whole entry fails to load, and `/bun-angular` imports
80
81
  `provideZonelessChangeDetection` (Angular 20+; called `provideExperimentalZonelessChangeDetection`
@@ -121,7 +122,8 @@ and is only ever asserted on — `createAutoMock`. Handed to the function under
121
122
  (`detectVpnClient(url, logger)`, `applyPreferredTracks(target, …)`, `setLocalConfigEnabled(storage, …)`),
122
123
  it has to satisfy `T` at the call site _and_ expose the spy helpers at the assertion, and
123
124
  `autoMocked<T>()` is that intersection — otherwise every call site needs an `asInstance()` and the
124
- noise scales with the number of them.
125
+ noise scales with the number of them. Both take the same second argument (`returns`, `name`, `strict`,
126
+ `observablePropsToSpyOn`).
125
127
 
126
128
  `createMock<T>()` is the one to reach for on data shapes — it returns a plain `T`, so it satisfies a
127
129
  `no-type-assertion` lint rule without an `eslint-disable` on every fixture.
@@ -172,8 +174,8 @@ out, and the one that costs an afternoon otherwise. `mock.repo.user.find()` chai
172
174
  but the last is a _read_. A node that is **called** returns what it was configured to return, and by
173
175
  default that is `undefined`, so `mockDeep<AppLogger>().channel('app').info('x')` is a `TypeError` at
174
176
  the second call — while `DeepMockProxy<AppLogger>` types it perfectly, so nothing warns. Pass
175
- `{ selfReturning: true }` for a fluent API, or use `createAutoMock<T>()` with
176
- `channel.mockReturnThis()` when only one method chains:
177
+ `{ selfReturning: true }` for a fluent API, or use
178
+ `createAutoMock<T>(undefined, { selfReturning: ['channel'] })` when only one method chains:
177
179
 
178
180
  ```ts
179
181
  const logger = mockDeep<AppLogger>({}, { selfReturning: true });
@@ -556,6 +558,7 @@ createSpyFromClass(MyService, {
556
558
  autoSpyAccessors: true, // discover every accessor on the prototype chain
557
559
  lazySpies: true, // build each method spy on first access ('proxy' for very wide classes)
558
560
  returns: { getProducts: of([]) }, // what a spied METHOD answers
561
+ selfReturning: ['where'], // a method that answers the double itself, for a chained call
559
562
  overrides: { products$: subject }, // a member that is not a method result
560
563
  });
561
564
  ```
@@ -569,6 +572,7 @@ createSpyFromClass(MyService, {
569
572
  | `lazySpies` | Behaviour-identical; only changes _when_ each spy is built. `'proxy'` also changes _what holds the name_. |
570
573
  | `strict` | Throw on a method nobody configured, instead of answering `undefined` (below). |
571
574
  | `onUnstubbedCall` | The general form of `strict`; its return value becomes the call's return value. |
575
+ | `selfReturning` | The named methods answer the double itself — a default like `returns`; a name in both answers `returns`. |
572
576
 
573
577
  **`instanceMethodsToSpyOn` is not an edge case — it is a top-5 option** (103 of ~370 spec files in
574
578
  the reference suite). Method discovery walks the _prototype chain_; a callable assigned to an
@@ -706,6 +710,33 @@ registerAutoSpyDefaults([
706
710
  A later row for a class an earlier row already named replaces it, exactly as a second call would.
707
711
  `AutoSpyDefaultEntry<T>` is the row type, for a row built outside the literal.
708
712
 
713
+ **An `InjectionToken` is a key too — import `registerAutoSpyDefaults` from `vitest-auto-spy/angular`
714
+ for it.** Same registry, same merge; the core export takes a class only, because the core entry may
715
+ not mention Angular's types. `provideAutoSpyForToken(TOKEN)` reads the registration exactly as
716
+ `provideAutoSpy(Class)` reads a class's — both of its arguments are merged over it, and a registered
717
+ `returns` stays a default a later `calledWith` / `resolveWith` wins over:
718
+
719
+ ```ts
720
+ import { registerAutoSpyDefaults } from 'vitest-auto-spy/angular';
721
+
722
+ registerAutoSpyDefaults(LOGGER, { returns: { info: undefined, err: undefined }, selfReturning: ['channel'] });
723
+ registerAutoSpyDefaults(NAVIGATION, { overrides: { activeRow$: of({}) }, returns: { setFocus: undefined } });
724
+
725
+ providers: [provideAutoSpyForToken(LOGGER), provideAutoSpyForToken(NAVIGATION, { activeRow$: rows$ })];
726
+ ```
727
+
728
+ A token row holds `AutoSpyTokenDefaults<T>`: what `createAutoMock` takes (`returns`, `selfReturning`,
729
+ `observablePropsToSpyOn`, `strict`, `name`) plus `overrides`, the seeds `provideAutoSpyForToken` takes
730
+ second. Keys are checked against the token's `T`; a table may mix class rows and token rows;
731
+ `clearAutoSpyDefaults(TOKEN)` from the same entry drops one. Handing a token to the **core**
732
+ `registerAutoSpyDefaults` fails with `TS2345 … 'InjectionToken<X>' is not assignable to parameter of
733
+ type 'ClassType<unknown>'` — the fix is the import, not a cast.
734
+
735
+ **`selfReturning` names the methods that answer the double itself.** `returns` cannot say it — the
736
+ double does not exist when the literal is written — and without it a chained call dies on
737
+ `undefined`. It works on every factory and in a registration; a registered chain takes a link back out
738
+ through the call site's `returns`, since lists only ever union.
739
+
709
740
  ### `strict` — a method nobody configured throws instead of answering `undefined`
710
741
 
711
742
  ```ts
@@ -723,19 +754,39 @@ Called as: Cart.checkout(1,'now')
723
754
  Also on `createAutoMock`, `provideAutoSpy`, and suite-wide as `setupAutoSpy({ strict: true })` — which
724
755
  reaches a double whichever bundle of the package built it: the default lives on `globalThis`. Before
725
756
  this release it lived in module scope, and a setup file's `strict: true` reached no double a spec built.
726
- Precedence, first one set wins: the double's `onUnstubbedCall` → the global `onUnstubbedCall` → the
727
- double's `strict` (**including `strict: false`**, the only way to exempt one double from a suite-wide
728
- default) → the global `strict`.
757
+ Precedence, first one set wins: the double's `onUnstubbedCall` → the double's explicit **`strict: false`**
758
+ (the only way to exempt one double from a suite-wide default, a global handler included) → the global
759
+ `onUnstubbedCall` → the double's `strict: true` → the global `strict`.
729
760
 
730
761
  - **It is not argument-level.** A `calledWith(1, 'now')` chain says the method is stubbed, so
731
762
  `checkout(9, 'later')` still answers `undefined`. Use `mustBeCalledWith` for that.
732
- - **`mockReturnValue` / `mockImplementation` / the `returns:` option replace the dispatch**, so they
733
- never reach the guard. Consequence: after the last `mockReturnValueOnce` the queue empties back
734
- onto the library dispatch and the next call **is** reported as unstubbed — seed
735
- `mockReturnValue(...)` too when a `Once` sequence is meant to run out.
763
+ - **`returns:` is a default in the spy's own container**: a `calledWith` / `resolveWith` / `failWith`
764
+ configured later wins for its arguments or supersedes it, every other call still gets it, and
765
+ `undefined` counts as configured. `returns: { save: undefined }` is how a `void` call is expected.
766
+ `selfReturning: ['channel']` is the same kind of default, and counts as configured too.
767
+ - **`mockReturnValue` / `mockImplementation` replace the dispatch**, so they never reach the guard —
768
+ and a `calledWith` configured after them is never consulted. After the last `mockReturnValueOnce`
769
+ the queue empties back onto the library dispatch and the next call **is** reported as unstubbed —
770
+ seed `mockReturnValue(...)` too when a `Once` sequence is meant to run out.
771
+ - **A throw something swallowed still fails the test.** Under `setupAutoSpy({ strict: true })` every
772
+ strict throw is recorded, and one that a `try`/`catch` in the code under test or an RxJS error with
773
+ no handler (its rethrow waits on a fake clock) kept from the test fails it after the test
774
+ (`swallowedStrictCalls`, `'throw'` by default with `strict: true`). Provoking one on purpose:
775
+ `expect(() => cart.total()).toThrow(…)` then `expect(takeStrictViolations()).toHaveLength(1)`.
736
776
  - **It does not reach** accessor spies, observable-property spies, `mockDeep` nodes, `console-spy`,
737
777
  `mockResourceProp`'s `reload` or a standalone `createFunctionSpy`. A strict double still answers
738
778
  `undefined` for an unconfigured getter or `items$`. `fillMissing` members **are** covered.
779
+ - **The getter and the stream are reported after the test instead** — a read cannot throw, because a
780
+ failure diff that prints the double reads it. `setupAutoSpy({ unconfiguredReads: 'warn' | 'throw' })`
781
+ (default `'off'`, not in the preset) reports a strict double's getter read that reached no
782
+ configuration and a subscription to a stream nothing fed **by the end of the test** — subscribe in
783
+ `beforeEach`, `nextWith` in the test is fine. Counted from setup's `beforeEach` to its `afterEach`,
784
+ so the spec's own hooks count. Configured means `accessorSpies.getters.x.mockReturnValue(…)` /
785
+ `mockImplementation`, `overrides: { x }` (call site or registration — a registered _list_ alone is
786
+ not), `mockReadonlyProp`; for a stream any of `nextWith` / `throwWith` / `complete` /
787
+ `returnSubject`. `undefined` meant: `mockReturnValue(undefined)`. `onUnstubbedRead({ className,
788
+ member, kind, count })` — suite-wide or per double, same precedence as `onUnstubbedCall` — takes the
789
+ findings instead of the report, from every double not `strict: false`: survey with it first.
739
790
  - **Angular lifecycle hooks are exempt.** `ngOnDestroy`, `ngOnInit`, `ngOnChanges`, `ngDoCheck` and the
740
791
  `ngAfter…` hooks answer `undefined` on a strict double: Angular calls `ngOnDestroy` itself on every
741
792
  provided value at teardown (a `createAutoMock` / `provideAutoSpyForToken` double always has one), and
@@ -823,6 +874,14 @@ const config = asSpy<FeatureFlagService>(TestBed.inject(FeatureFlagService)); //
823
874
  const config = injectSpy<FeatureFlagService>(FeatureFlagService); // ✅
824
875
  ```
825
876
 
877
+ It applies to `createSpyFromClass` with a configuration too, in one combination: an accessor list
878
+ (or `overrides`) **and** `returns` on a generic class. TypeScript checks a generic class argument
879
+ after the configuration, reads `T` back from `gettersToSpyOn: ['remoteConfig']` as
880
+ `{ remoteConfig: any }`, and fails with `'isKeyEnabled' does not exist in type
881
+ 'MethodReturns<{ remoteConfig: any; }>'`. Spell it out — `createSpyFromClass<RemoteConfigService>(…)`.
882
+ `provideAutoSpy`, `overrideAutoSpy` and `overrideComponentProvider` (`/angular`) take `T` from the
883
+ class alone, so there the inferred form compiles.
884
+
826
885
  **A declared default now reaches the double, and used not to.** `class RemoteConfigService<T =
827
886
  RemoteConfigDefaults>` handed to `createSpyFromClass` / `injectSpy` inferred `T` as `unknown`, so
828
887
  every member typed against it read as `unknown` on a class that had said exactly what it should be.
@@ -1601,7 +1660,8 @@ setupAutoSpy({ preset: 'strict' });
1601
1660
  Sets `duplicateCopies`, `propsOutsideHooks`, `guardGlobals`, `prototypePollution`, `strayConsole` and
1602
1661
  `misconfiguration` to `'throw'`, turns `strayTimers` on, and `strayRejections` on when zone.js is
1603
1662
  loaded. An option passed alongside still wins. **Not** included: `strict` (strict doubles change what
1604
- an unconfigured call returns — a semantic switch, not a grade; the name was taken, hence `preset`),
1663
+ an unconfigured call returns — a semantic switch, not a grade; the name was taken, hence `preset`) and
1664
+ `unconfiguredReads`, its read side (survey with `onUnstubbedRead` before turning it on),
1605
1665
  `blockNetwork` (changes the code under test), `restoreMocks` (drops `beforeAll` spies), failing on
1606
1666
  stray-timer counts (the sweep fails the file from `afterAll`, and a callback scheduled after the
1607
1667
  previous file's sweep is charged to the next — opt in with
@@ -1741,6 +1801,34 @@ State is per element, so an ad and the content report different durations.
1741
1801
  the record and fires `timeupdate` too — `media.set()` is not the only way in, and the component's own
1742
1802
  handler runs where it used to stay unrun while the assertion read the new value.
1743
1803
 
1804
+ ### `localStorage` and `sessionStorage`
1805
+
1806
+ Do not write a `TestingStorage` class per project. `stubWebStorage()` installs an in-memory `Storage`
1807
+ for this test — `getItem` / `setItem` / `removeItem` / `clear` / `key` / `length`, string coercion
1808
+ as the platform does it — and `snapshot()` is the plain record to assert on:
1809
+
1810
+ ```ts
1811
+ import { stubWebStorage, type WebStorageStub } from 'vitest-auto-spy/dom-stubs';
1812
+
1813
+ let local: WebStorageStub;
1814
+
1815
+ beforeEach(() => {
1816
+ local = stubWebStorage('localStorage', { items: { token: 'abc' } }); // or 'sessionStorage'
1817
+ });
1818
+
1819
+ it('forgets the token on logout', () => {
1820
+ session.logout();
1821
+ expect(local.snapshot()).toEqual({});
1822
+ });
1823
+ ```
1824
+
1825
+ It goes through `mockValueProp`, so `restoreMockedProps()` (and `setupAutoSpy()` between tests) puts
1826
+ the previous storage back; install it in `beforeEach`. It also lands on `document.defaultView` when
1827
+ that is a separate object. It is not `restoreWebStorage()`: that one repairs a broken environment
1828
+ once and leaves a working storage alone; this one replaces whatever is there, for one test, and
1829
+ installs even in a `node` environment because the spec asked for it. Named-property access
1830
+ (`localStorage.token`, `Object.keys(localStorage)`) does not see the items — read through the API.
1831
+
1744
1832
  ### A module mock that did nothing
1745
1833
 
1746
1834
  `vi.mock()` is the one thing in a ported suite that fails **silently**. Under a bundler
@@ -2151,8 +2239,9 @@ and the next line reads the settled value.
2151
2239
 
2152
2240
  Three things to know before reaching for it:
2153
2241
 
2154
- - **It does not re-export the core.** The one subpath that does not: it is a companion to
2155
- `vitest-auto-spy/angular`, which stays the import for spies, `TestBed` helpers and `settleResource`.
2242
+ - **It does not re-export the core** — nor does `/angular-router`; every other subpath does. It is a
2243
+ companion to `vitest-auto-spy/angular`, which stays the import for spies, `TestBed` helpers and
2244
+ `settleResource`.
2156
2245
  Staying narrow is what keeps `@angular/common` — an **optional** peer — out of every other entry.
2157
2246
  - **`settleResource` is unchanged and still the answer** whenever the wait is not tied to one
2158
2247
  request: a `resource()` with an async loader, an `rxResource`, a reload, anything not HTTP.
@@ -2161,6 +2250,52 @@ Three things to know before reaching for it:
2161
2250
  suite using `provideHttpTesting()` everywhere the diagnostic is redundant; keep it on while any
2162
2251
  file still configures HTTP testing by hand.
2163
2252
 
2253
+ ### `ActivatedRoute` from one record — `vitest-auto-spy/angular-router`
2254
+
2255
+ ```ts
2256
+ import { injectActivatedRoute, provideActivatedRoute } from 'vitest-auto-spy/angular-router';
2257
+
2258
+ TestBed.configureTestingModule({
2259
+ providers: [provideActivatedRoute({ params: { id: '7' }, queryParams: { tab: 'reviews' } })],
2260
+ });
2261
+
2262
+ const fixture = TestBed.createComponent(ProductPage);
2263
+
2264
+ injectActivatedRoute().setParams({ id: '8' }); // params + paramMap emit; snapshot.params already agrees
2265
+ fixture.detectChanges();
2266
+ ```
2267
+
2268
+ **Do not hand-write an `ActivatedRoute` double, and do not `provideAutoSpy(ActivatedRoute)`.** Its
2269
+ streams and its snapshot are instance fields: the spy has neither, and a `useValue` has whichever half
2270
+ its author thought of — `route.paramMap.pipe(…)` throws on the `{ snapshot }` one, `route.snapshot`
2271
+ is `undefined` on the `{ params: of(…) }` one, and a spec that updates one half by hand tests a route
2272
+ no navigation produces. `provideActivatedRoute(init)` provides **Angular's own `ActivatedRoute`**
2273
+ built over one record, so every stream, both `ParamMap`s and `snapshot` read the same values.
2274
+
2275
+ | Call | Does |
2276
+ | -------------------------------------- | ------------------------------------------------------------------------------------------------------ |
2277
+ | `provideActivatedRoute(init?)` | a `FactoryProvider` — a fresh route per injector; `init`: `params`, `queryParams`, `data`, `fragment`, `url`, `outlet`, `component`, `routeConfig` |
2278
+ | `injectActivatedRoute(injector?)` | the handle: `.route`, `setParams`, `setQueryParams`, `setData`, `setFragment`, `setUrl`, `set({ … })` |
2279
+ | `createActivatedRoute(init?)` | the same handle without a `TestBed` — for `new Page(route)`, or a guard given `route.snapshot` |
2280
+
2281
+ A setter behaves like the router after a navigation: it **replaces** (not merges) that part, builds
2282
+ a new snapshot first, then emits only the streams whose value changed (router equality: same keys,
2283
+ arrays as sorted sets), in the order `queryParams`, `fragment`, `params`, `url`, `data`. Setting
2284
+ an equal value emits nothing; a string `url` is split on `/`.
2285
+
2286
+ Four things to know:
2287
+
2288
+ - **List it after `provideRouter()`** — the later provider of `ActivatedRoute` wins, and
2289
+ `injectActivatedRoute()` throws naming the one that did. With the real router present, the double
2290
+ still works as `relativeTo` for `router.createUrlTree`.
2291
+ - **One node, no tree.** `root` is the route itself, `parent` / `firstChild` are `null`. For
2292
+ `route.parent.params` patch that member with `mockReadonlyProp`, or use `RouterTestingHarness`.
2293
+ - **No `title`, no navigation, no input binding** — `title` emits `undefined`, `Router.navigate`
2294
+ does not move it (the setters do), and `withComponentInputBinding()` is the outlet's job
2295
+ (`fixture.componentRef.setInput`).
2296
+ - **Its own entry, like `/angular-http`.** It does not re-export the core, imports no runner, and is
2297
+ the only file that reaches `@angular/router` — an optional peer.
2298
+
2164
2299
  ### Which collaborators the code asked for — `trackInjections`
2165
2300
 
2166
2301
  Do **not** reach for `vi.mock('@app/services')` to answer "was this collaborator used". Register the
@@ -2359,12 +2494,16 @@ spec — after which `Spy<Mock>` and `Spy<Interface>` disagree and somebody cast
2359
2494
  **The second argument is not optional as often as it looks.** A spy answers `undefined` until it is
2360
2495
  told otherwise, and that is fatal the moment the code under test _chains_ off it — a constructor
2361
2496
  doing `inject(LOGGER).channel('auth').debug('…')` dies on the `.debug` of `undefined` before the
2362
- spec's first line runs, because nothing in production wrote `?.` there. Seed the link:
2497
+ spec's first line runs, because nothing in production wrote `?.` there. Name the link:
2363
2498
 
2364
2499
  ```ts
2365
- provideAutoSpyForToken(LOGGER, { channel: vi.fn().mockReturnThis() });
2500
+ provideAutoSpyForToken(LOGGER, undefined, { selfReturning: ['channel'] });
2366
2501
  ```
2367
2502
 
2503
+ `channel` stays a spy (assertable, and configured under `strict`) and answers the double itself.
2504
+ When every file wants it, register it once — `registerAutoSpyDefaults(LOGGER, { selfReturning:
2505
+ ['channel'] })` from `vitest-auto-spy/angular` (§5) — and the provider is `provideAutoSpyForToken(LOGGER)`.
2506
+
2368
2507
  For a chain more than one link long, `mockDeep<T>()` is the double that answers every level (§2).
2369
2508
 
2370
2509
  ### A host for a directive under test
@@ -2392,6 +2531,33 @@ _is_ declared; `NG0304` calls a missing directive a missing component; a bare at
2392
2531
  nothing at all). `schemas: [NO_ERRORS_SCHEMA]` next to a standalone component is a dead entry —
2393
2532
  schemas apply to a testing module's `declarations` only.
2394
2533
 
2534
+ ### A stand-in for a child — `createComponentStub`
2535
+
2536
+ Do not hand-write `class MockChartComponent` with a copied selector: nothing checks the copy, so a
2537
+ renamed input leaves the parent's binding pointing at nothing and the spec green. Build the stub
2538
+ from the real class's compiled definition instead:
2539
+
2540
+ ```ts
2541
+ import { createComponentStub } from 'vitest-auto-spy/angular';
2542
+
2543
+ const ChartStub = createComponentStub(ChartComponent); // also a directive or a pipe
2544
+
2545
+ TestBed.configureTestingModule({ imports: [DashboardComponent] });
2546
+ TestBed.overrideComponent(DashboardComponent, { remove: { imports: [ChartComponent] }, add: { imports: [ChartStub] } });
2547
+
2548
+ const chart = fixture.debugElement.query(By.directive(ChartStub)).componentInstance;
2549
+ expect(chart.series()).toEqual([1, 2, 3]); // a signal input stays a signal input
2550
+ chart.pointSelected.emit(2); // outputs are EventEmitters; a model() stays a model
2551
+ ```
2552
+
2553
+ Copied from `ɵcmp` / `ɵdir` / `ɵpipe`: the selector, every input under its public name (transforms
2554
+ included), every output, `exportAs`, a pipe's name and purity. Not copied: the template (the stub
2555
+ renders one `<ng-content>` per slot the real one projects — `{ template }` in the third argument
2556
+ replaces it), host bindings, providers, lifecycle hooks, queries. The second argument seeds members
2557
+ per instance — a method the parent calls through `viewChild`, a pipe's `transform` (identity by
2558
+ default). With `renderShallow`: `renderShallow(Parent, { keepTemplate: true, keepChildren: [ChartStub] })`
2559
+ — the real child is dropped as a component import and the stub is the one child left.
2560
+
2395
2561
  ### Patching a property of a spy
2396
2562
 
2397
2563
  `mockReadonlyProp` / `mockValueProp` / `mockSignalProp` accept the `Spy<T>` that `injectSpy` returns,
@@ -2635,17 +2801,24 @@ blanket downgrade so those keep their severity; do not copy the two names into a
2635
2801
  | `no-passthrough-console-spy` | `error` | suggest | `vi.spyOn(console, m)` nothing gives an implementation — it calls through and prints → `installConsoleSpies()` + `consoleXSpy`, or `.mockImplementation(() => undefined)` |
2636
2802
  | `no-console-in-spec` | `error` | — | a spec calling `console.x(…)` itself, or `console.x = …`, which nothing restores → absorb the code's output through `vitest-auto-spy/console` |
2637
2803
  | `no-import-time-console-spies` | `error` | — | an import of `vitest-auto-spy/console` in a file that never calls `installConsoleSpies()` — the import installs once per worker and silences every later file → `installConsoleSpies()` in `beforeEach`, `restoreConsole()` in `afterEach` |
2804
+ | `no-mistyped-use-value` | `error` | — | `{ provide: TOKEN, useValue }` whose value is not assignable to the primitive `T` of `InjectionToken<T>` (string, number, boolean, bigint, enum, their literals, `null`, `undefined`) — `useValue` is `any`, so `{}` for a `boolean` token compiles and is truthy. **Type-aware**: silent without `parserOptions.project`; object-typed tokens are `no-unknown-use-value-key`'s |
2805
+ | `no-unknown-use-value-key` | `error` | — | a key of an object `useValue` literal the provided type does not have — `T` of `InjectionToken<T>`, or the instance type of a `provide:` class; `{ provide: ActivatedRoute, useValue: { queryParams$: … } }` compiles, since `useValue` is `any`. Keys only, never assignability (a partial fixture is fine). **Type-aware**; silent on `any` / `unknown` / `object`, an index signature, a spread's keys, `multi: true` |
2806
+ | `no-instance-lifecycle-spy` | `warn` | — | `vi.spyOn(instance, 'ngOnInit')` (and `ngOnDestroy`, `ngDoCheck`, `ngAfterContent*`, `ngAfterView*`) — a view calls the hook read off the prototype, so the instance spy is never called and its stub never runs → `vi.spyOn(Cls.prototype, …)` before `createComponent`, or assert the effect. `ngOnChanges` is exempt: Angular calls it through the instance |
2807
+ | `no-ts-expect-error-on-double` | `error` | — | `@ts-expect-error` / `@ts-ignore` above `nextWith`, `resolveWith`, `mockReturnValue`, `returnValue`, `calledWith(…)` and the other helpers that check a stub against the method's signature → an overloaded method takes `Spy<X, { overload: { m: 'first' } }>`; otherwise the fixture is the wrong shape, checked against `ReturnType<X['m']>`. A reason after the directive does not silence it; a deliberate out-of-type value keeps it under `eslint-disable-next-line … -- <why>` |
2808
+ | `no-constant-expect` | `error` | — | `expect(true).toBe(true)`, `expect({ … }).toBeDefined()` — a value the spec spelled out, under a matcher whose answer it already fixes (`toBe` / `toEqual` / `toStrictEqual` against a literal; `toBeTruthy`, `toBeDefined`, `toBeNull`… for any literal) → assert on what the code produced, or `expect.fail(…)` for an unreachable branch |
2809
+ | `no-compile-components` | `error` | suggest | `compileComponents()` under a builder that inlines `templateUrl` / `styleUrls` — a promise already settled → delete it, and the `async` of a hook that awaits nothing else. **Silent until** `['error', { builder: 'inline-resources' }]`: under a JIT setup that loads resources at run time the call is load-bearing |
2638
2810
  | `jasmine-namespace-without-entry` | `error` | — | `.and` / `.calls` / `.withArgs` on a library spy in a file that installs the compat layer nowhere — option: `{ setupModules: […] }` |
2639
2811
  | `no-jasmine-globals` | `error` | — | `jasmine.*`, bare `spyOn(` / `spyOnProperty(` / `spyOnAllFunctions(` / `fail(` / `pending(`, `.withContext(` |
2640
2812
  | `no-save-arguments-by-value` | `error` | — | `spy.calls.saveArgumentsByValue()` — a no-op here, so the spec silently asserts on post-mutation state |
2641
2813
  | `prefer-native-spy-api` | `error` | `--fix` / suggest | `.and` / `.calls` where the spy's own API says the same thing — turn it on for the last mile off the jasmine shim |
2642
2814
 
2643
- Twenty-eight rules, **every one an `error` since 4.0.0 except `prefer-render-shallow`,
2644
- `no-stub-class-double` and `no-structural-double`**; three fix on their own, nine offer suggestions. Twenty-seven are syntactic; `no-private-member-access` is the one
2645
- that reads types, and it reports nothing at all without `parserOptions.project` / `projectService`
2646
- rather than guessing. The config used to be a graded mix of `error` / `warn` / `off`, which decided for the
2815
+ Thirty-four rules, **every one an `error` since 4.0.0 except `prefer-render-shallow`,
2816
+ `no-stub-class-double`, `no-structural-double` and `no-instance-lifecycle-spy`**; three fix on their own, ten offer suggestions. Thirty-one are syntactic; `no-private-member-access`, `no-mistyped-use-value` and
2817
+ `no-unknown-use-value-key` read types, and all three report nothing at all without `parserOptions.project` / `projectService`
2818
+ rather than guessing. `no-compile-components` waits the same way for a fact no file holds — which
2819
+ builder the project has — and reports nothing until `{ builder: 'inline-resources' }` states it. The config used to be a graded mix of `error` / `warn` / `off`, which decided for the
2647
2820
  consumer how much each finding mattered — a `warn` nothing reads is `off` with extra output. The
2648
- three `warn`s left are not judgements about how much a finding matters. `prefer-render-shallow` is
2821
+ four `warn`s left are not judgements about how much a finding matters. `prefer-render-shallow` is
2649
2822
  about the _kind_ of finding: every other rule names something wrong or dead, while this one names a
2650
2823
  file that could render more cheaply, and `renderShallow` is a migration a suite either takes or does
2651
2824
  not. At `error` the plugin would gate that migration — 491 findings across 398 of one consumer's
@@ -2658,7 +2831,9 @@ and moved a long way inside the release: measured on the same 1759 files, the tw
2658
2831
  reports in 8 files and 115 in 74, and are 10 in 7 and 5 in 4 once `prefer-provide-auto-spy` learnt to
2659
2832
  follow a name into a `useValue` — 112 of those doubles are handed to Angular DI one name away, where
2660
2833
  a `provide:` settles it. That rule reports **154 times across 87 files** on the same suite, all at
2661
- `error`. Set any of the three `warn`s to `'error'` once the batch is done. Three of
2834
+ `error`. `no-instance-lifecycle-spy` is on the evidence too: Angular never calls an instance spy on a
2835
+ hook it read off the prototype, but a spec that calls `component.ngOnInit()` itself does, and so does
2836
+ the injector for a service's `ngOnDestroy`. Set any of the four `warn`s to `'error'` once the batch is done. Three of
2662
2837
  them can report on a _correct_ project, and only one has an option:
2663
2838
  `jasmine-namespace-without-entry` takes `['error', { setupModules: ['./test-setup'] }]`, naming the
2664
2839
  file where `enableJasmineCompat()` is called; `prefer-native-spy-api` goes `'off'` for as long as a
@@ -2774,6 +2949,18 @@ written above it inside a `createComponent` helper. Configure the double after t
2774
2949
  (`injectSpy(X)` in the test), or keep the access lazy: `const api = () => injectSpy(Api)`. The check
2775
2950
  is order-free by design, since a helper declared above the hook still runs after it.
2776
2951
 
2952
+ `no-ts-expect-error-on-double` reports the suppression, not the reason written after it. On one
2953
+ 1759-file suite it reports 34 directives in 15 files and **every one carries a reason** — so an
2954
+ escape for "a directive with a reason" would have silenced all of them. Four sat on overloaded
2955
+ clients, which `overload` repairs (§5); seven blamed "the collapsed generic" for a fixture the real
2956
+ instantiation rejects as well; nineteen hid a fixture or a production type that disagrees with the
2957
+ declared one. Four were deliberate — a value outside the declared type, to reach a default branch —
2958
+ and that is the case a per-line disable is for:
2959
+ `// eslint-disable-next-line vitest-auto-spy/no-ts-expect-error-on-double -- <why>` above the
2960
+ directive. The report sits on the directive's line so that comment reaches it. `rejectWith`,
2961
+ `failWith` and `throwWith` are not read: their parameter is `unknown`, so a directive there
2962
+ suppresses something other than the stub.
2963
+
2777
2964
  The legacy `.eslintrc` `plugins: []` form cannot work — it resolves names to `eslint-plugin-*`
2778
2965
  packages, which a subpath export can never be.
2779
2966
 
@@ -2798,6 +2985,7 @@ packages, which a subpath export can never be.
2798
2985
  | `extendWithAutoSpies needs Vitest 4.1 or newer` | the `test` handed in has only the object-form `extend` (Vitest ≤ 4.0); the builder form the helper is written against arrived in 4.1 | upgrade Vitest, or keep `provideAutoSpy` + `injectSpy` in a `beforeEach` until then |
2799
2986
  | `advanceTimers() requires fake timers` | no fake timers installed | `setupFakeTimers()` or `vi.useFakeTimers()` first |
2800
2987
  | `Nothing configured X.method, and strict mode is on` | a strict double was asked for a method no line configured | configure it (`mockReturnValue` / `resolveWith` / `nextWith` / `calledWith`), or `{ strict: false }` on that double (§5) |
2988
+ | `X.member was read N times and nothing configured it, and strict mode is on` (or `was subscribed to N times and nothing fed it`), after the test | `setupAutoSpy({ unconfiguredReads })` — the code under test read a strict double's spied getter and got `undefined`, or subscribed to its observable property and nothing ever emitted | configure it: `accessorSpies.getters.member.mockReturnValue(…)`, `overrides: { member }`, `mockReadonlyProp`; `nextWith` / `returnSubject` / `complete` for a stream; `mockReturnValue(undefined)` when `undefined` is the answer meant; `{ strict: false }` on that double (§5) |
2801
2989
  | `[vitest-auto-spy] "…" wrote to the console N time(s) and nothing absorbed it` | `setupAutoSpy({ strayConsole })` — the test printed, and nothing that does not call through stood on `console`: no `/console` spy installed for it, no `mockImplementation`. A bare `vi.spyOn(console, m)` calls through, and a `console.warn` from this library counts too| absorb and assert: `installConsoleSpies()` in a `beforeEach`, then `expect(consoleErrorSpy)…`; or fix the code that printed. Importing a spy installs nothing under the guard. `strayConsole: { allow: [...] }` only for environment noise no spec can reach |
2802
2990
  | `… wrote to the console N time(s) outside any test` | output while the file was imported, in a `beforeAll` / `afterAll`, from a callback after its test ended, or from a test whose `afterEach` never ran — the frame names the line | move the work into a test and absorb it there; a callback firing late is a leak — clear it where it is scheduled |
2803
2991
  | `setupAutoSpy({ strict: true })` has no effect — no double throws, a suite with it on stays green | before this release the default lived in module scope, and `/setup` and the factory bundles each carried a copy; a 1759-file consumer ran 12 717 tests green with it on | upgrade — the default, `onUnstubbedCall` and `setSpyEngine()` now live on `globalThis` |
@@ -2842,6 +3030,8 @@ packages, which a subpath export can never be.
2842
3030
  | `TS2739` / `TS2740` / `TS2345` with `Spy<X>` on the left | a spy handed to an API typed against the class | `asInstance(spy)` (§6) |
2843
3031
  | `is missing the following properties: _private, …` | declared as Vitest's `Mocked<T>` | declare `Spy<T>` (§6) |
2844
3032
  | `AddPromiseSpyMethods<unknown>` vs `WithMockReturnValue<…>` | a generic class inferred as `Service<any>` | `asSpy<Service>(…)` / `injectSpy<Service>(…)` (§6) |
3033
+ | `createComponentStub(): X carries no ɵcmp, ɵdir or ɵpipe to copy` | the class is not an Angular declaration, or the import resolved to `undefined` (a barrel split across chunks) | pass the `@Component` / `@Directive` / `@Pipe` class, imported from its own file (§13) |
3034
+ | `'isKeyEnabled' does not exist in type 'MethodReturns<{ remoteConfig: any; }>'` | generic class: `createSpyFromClass(Config, { gettersToSpyOn: ['remoteConfig'], returns: { … } })` reads `T` back from the list, because the generic class argument is checked after the configuration | generic class: spell out the type argument — `createSpyFromClass<Config>(Config, …)`; `provideAutoSpy` from `/angular` infers it (§6) |
2845
3035
  | `'addEventListener' called on an object that is not a valid instance of EventTarget` | Node's `AbortSignal` under jsdom + zone.js | `stubAbortController()` (§12) |
2846
3036
  | `vi.requireMock is not a function` | a mechanical `jest.` → `vi.` rename | there is no equivalent — provide the double through the TestBed instead |
2847
3037
  | a `vi.mock()` factory that never applies, only sometimes | under `isolate: false` the module was already in the worker's graph | do not mock it; inject the dependency, or `vi.hoisted()` + a real seam |
@@ -2858,7 +3048,7 @@ packages, which a subpath export can never be.
2858
3048
  | a spec dying on the runner's 5 s file timeout right after `await stable(fixture)` | the fixture never stabilised — an unflushed request, a real `setInterval` | `stable` now fails at 2000 ms naming the cause; raise `{ timeout }` only once neither is true |
2859
3049
  | `flushEventLoopUntil` timing out on the **first** such test only, the rest green | a cold dynamic `import()` outran the turn budget; later tests hit the module cache | `await settleDynamicImport(() => import('…'))` — await the module, do not count turns |
2860
3050
  | `Expected to be running in 'ProxyZone', but it was not found` | `zone.js/testing` patches jasmine/mocha/jest, not Vitest | `import 'vitest-auto-spy/zone'` after zone.js, with `globals: true` (§14) |
2861
- | `nextWith` demanding `HttpEvent<T>` on a generated API client | `Parameters`/`ReturnType` read the **last** overload | `asSpy<Client, { overload: 'first' }>(…)`, or `Overload<M, 0>` |
3051
+ | `nextWith` demanding `HttpEvent<T>` on a generated API client | `Parameters`/`ReturnType` read the **last** overload | `asSpy<Client, { overload: 'first' }>(…)`, or `Overload<M, 0>` — never `@ts-expect-error`, which `no-ts-expect-error-on-double` reports (§16) |
2862
3052
  | `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) |
2863
3053
  | `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` |
2864
3054
  | `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) |
@@ -2878,9 +3068,17 @@ packages, which a subpath export can never be.
2878
3068
  | `createNestUnit(X): A -> B -> A is a cycle among the classes built for real` | two exposed / `useClass` classes depend on each other; the helper does not resolve `forwardRef` cycles | expose one side less, or provide it |
2879
3069
  | `createNestUnit(X).spies.get(Y): the unit never asked for that token` | same guard as `createWithAutoSpies` — the spy would not be the one the unit uses | stub the token the unit actually injects (the message lists the auto-spied ones) |
2880
3070
  | `createNestUnit(X).spies.get(Y): Y is in \`expose\`, so the unit got a real instance` | an exposed class is real, not a spy | read the spies of its own collaborators, or drop it from `expose` |
3071
+ | `expect(component.ngOnInit).toHaveBeenCalled()` fails after `fixture.detectChanges()`, or a hook's `.mockImplementation` never runs | the spy was put on the **instance**; a view calls the hook it read off the class prototype when the component was created | `vi.spyOn(Cls.prototype, 'ngOnInit')` before `TestBed.createComponent`, or assert what the hook does — `no-instance-lifecycle-spy` (§16) |
3072
+ | `TS2345: Argument of type 'InjectionToken<X>' is not assignable to parameter of type 'ClassType<unknown>'`, on `registerAutoSpyDefaults` | the core entry's `registerAutoSpyDefaults` takes a class only — it may not name Angular's token type | import `registerAutoSpyDefaults` (and `clearAutoSpyDefaults`) from `vitest-auto-spy/angular`, which also takes an `InjectionToken` (§5) |
3073
+ | `selfReturning names 'x', which is not a spied method` | the name is not a method of the double — a typo, or a restricting `onlyMethodsToSpyOn` left it out; on a type-driven double, `then` and `constructor` are never spies | fix the name or the whitelist; the value is silently never returned otherwise (§5) |
3074
+ | a spec green over a `useValue` fixture whose key the code never reads — `queryParams$` on an `ActivatedRoute` | `useValue` is `any`, so a renamed or misspelled key of an object literal compiles | the member's real name — `no-unknown-use-value-key` (§16), with type information; or `provideAutoSpy(X, { overrides })`, which the compiler checks |
3075
+ | a spec runs down the "browser" (or any flag-on) branch whatever its `useValue` says | `{ provide: IS_BROWSER, useValue: {} }` for an `InjectionToken<boolean>` — `useValue` is `any`, and an object is truthy | a value of the token's type (`useValue: false`) — `no-mistyped-use-value` (§16), with type information |
2881
3076
  | `no request matched …` (with the requests that were made listed) | the URL, verb or predicate does not describe anything the code under test sent, or nothing subscribed | read the list in the message — it is the requests that were actually made; then fix the URL, add `{ method }`, or subscribe (§13) |
2882
3077
  | `this TestBed has no HttpTestingController` | `expectRequest` / `expectNoRequest` on a module that never got the testing backend | `TestBed.configureTestingModule({ providers: [...provideHttpTesting()] })` from `vitest-auto-spy/angular-http` (§13) |
2883
3078
  | `the test ended with N unanswered request(s)` | `provideHttpTesting({ verifyOnTeardown })` found a request the spec never flushed | answer it (`await expectRequest(url).flush(body)`), assert its absence (`expectNoRequest(url)`), or `{ verifyOnTeardown: false }` (§13) |
3079
+ | `injectActivatedRoute(): nothing provides ActivatedRoute here` | no `ActivatedRoute` provider in the injector it read | `provideActivatedRoute({ … })` from `vitest-auto-spy/angular-router` in `providers`; `injectActivatedRoute(fixture.debugElement.injector)` for a component-level one (§13) |
3080
+ | `the ActivatedRoute here is … not one provideActivatedRoute() built` | a later provider of `ActivatedRoute` won — `provideRouter()`, `RouterModule`, a `useValue`, `provideAutoSpy(ActivatedRoute)` | list `provideActivatedRoute()` last, or drop the other provider (§13) |
3081
+ | `provideActivatedRoute: the installed @angular/router does not wire ActivatedRoute …` | a router major builds `ActivatedRoute` with different internal constructors | report it with the `@angular/router` version; provide the route by hand until then (§13) |
2884
3082
 
2885
3083
  **Seven of these are library defects, not spec ones.** On anything below 3.8.0, upgrade and change
2886
3084
  nothing in the spec: `of(double)` never emitting; `accessorSpies.setters.X` still `undefined` after
@@ -2912,7 +3110,10 @@ diagnostic and is free to change: print it, never assert on it.
2912
3110
  | `let s: MyService = createSpyFromClass(MyService)` | `let s: Spy<MyService> = …` |
2913
3111
  | `createSpyFromClass(X) as unknown as X` | `asInstance(createSpyFromClass(X))` |
2914
3112
  | `{ provide: X, useValue: { a: vi.fn(), b: vi.fn() } }` | `provideAutoSpy(X)` |
3113
+ | `{ provide: ActivatedRoute, useValue: { snapshot: { params } } }` | `provideActivatedRoute({ params })` — streams and snapshot from one record |
2915
3114
  | `vi.spyOn(TestBed.inject(X), 'method')` | `injectSpy(X).method` |
3115
+ | `vi.spyOn(component, 'ngOnInit')` after `createComponent` | `vi.spyOn(Cls.prototype, 'ngOnInit')` before it, or assert the effect |
3116
+ | `{ provide: IS_BROWSER, useValue: {} }` for an `InjectionToken<boolean>` | `useValue: false` — a value of the type the token declares |
2916
3117
  | `Object.defineProperty(service, 'ready', { value: true })` | `mockReadonlyProp(service, 'ready', true)` |
2917
3118
  | `source$.subscribe(v => expect(v).toBe(1))` | `await expect(expectEmission(source$)).resolves.toBe(1)` |
2918
3119
  | `await lastValueFrom(done$, { defaultValue: undefined })` | `await expectCompletion(done$)` |
@@ -2947,6 +3148,8 @@ diagnostic and is free to change: print it, never assert on it.
2947
3148
  | `.overrideProvider(X, provideAutoSpy(X))` (works, but says the wrong thing) | `.overrideProvider(X, overrideAutoSpy(X))` |
2948
3149
  | `TestBed.overrideComponent` to swap a provider | `overrideComponentProvider(Cmp, X)` |
2949
3150
  | `{ target, isIntersecting } as unknown as IntersectionObserverEntry` | `intersectionEntry(target, true)` |
3151
+ | `@Component({ selector: 'app-chart' }) class MockChartComponent { @Input() … }` | `createComponentStub(ChartComponent)` — the selector cannot drift |
3152
+ | a `TestingStorage` class assigned to `globalThis.localStorage` | `stubWebStorage('localStorage')`, restored with the other patches |
2950
3153
  | an assertion containing a date, with no clock set | `mockSystemTime(iso)` first |
2951
3154
  | `configureTestingModule` inside every `it()` | one per `describe` |
2952
3155
  | `vi.mock('@angular/core')` to neutralise `effect()` | set the signals, `await stable(fixture)`, assert the result |