vitest-auto-spy 5.46.0 → 5.48.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 +2 -2
- package/CHANGELOG.md +79 -1
- package/README.md +42 -26
- package/agent-docs/adapters.md +9 -9
- package/agent-docs/angular.md +8 -3
- package/agent-docs/anti-patterns.md +3 -2
- package/agent-docs/errors.md +1 -1
- package/agent-docs/eslint.md +25 -5
- package/agent-docs/setup.md +7 -3
- package/dist/angular-http.d.ts +1 -1
- package/dist/angular-http.js +12 -1
- package/dist/angular-matchers.d.ts +18 -2
- package/dist/angular-matchers.js +3 -2
- package/dist/angular.d.ts +1 -1
- package/dist/angular.js +8 -1
- package/dist/bun-angular.d.ts +1 -1
- package/dist/bun-angular.js +8 -1
- package/dist/cli.js +7 -1
- package/dist/console.d.ts +21 -1
- package/dist/console.js +12 -2
- package/dist/eslint-plugin.cjs +122 -3
- package/dist/eslint-plugin.d.ts +11 -23
- package/dist/setup.d.ts +21 -1
- package/dist/setup.js +47 -2
- package/dist/{track-signal-runs-CyPA-p4I.d.ts → track-signal-runs-CUdp5dJZ.d.ts} +24 -1
- package/package.json +1 -1
- package/skills/vitest-auto-spy/SKILL.md +150 -139
package/AGENTS.md
CHANGED
|
@@ -81,7 +81,7 @@ Add-ons, orthogonal to the runner:
|
|
|
81
81
|
| --- | --- | --- |
|
|
82
82
|
| Observable spies | `import 'vitest-auto-spy/rxjs'` | `nextWith` & friends. **Side-effect import, once**, in a setup file, a spec, or a `.d.ts` the `tsconfig` includes (§4) |
|
|
83
83
|
| 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 |
|
|
84
|
-
| Console spies | `vitest-auto-spy/console` | silent typed spies over the global `console` — `installConsoleSpies()` per test, `restoreConsole()` after; `consoleOutput()` is everything logged, keyed by channel |
|
|
84
|
+
| Console spies | `vitest-auto-spy/console` | silent typed spies over the global `console` — `useConsoleSpies()` in the `describe` (or `installConsoleSpies()` per test, `restoreConsole()` after); `consoleOutput()` is everything logged, keyed by channel |
|
|
85
85
|
| DOM stubs | `vitest-auto-spy/dom-stubs` | `stubIntersectionObserver` / `stubResizeObserver` / `stubMutationObserver` / `stubObserver`, `stubMediaElement`, `stubAbortController`, `stubWebStorage` (§12), `stubAnimationFrame`, `stubElementRect`, `intersectionEntry` / `resizeEntry` / `mutationRecord`. **Moved off the root in 4.0.0** |
|
|
86
86
|
| Run diagnostics | `vitest-auto-spy/diagnostics` | `compareTestRuns`, `summarizeTestRun`, `formatTestRunComparison`, `diffByField`. **Moved off the root in 4.0.0** |
|
|
87
87
|
| Angular HTTP | `vitest-auto-spy/angular-http` | `provideHttpTesting`, `expectRequest` — `httpResource()` / `HttpClient` (§13). Optional `@angular/common` peer, this entry only |
|
|
@@ -534,7 +534,7 @@ In [`agent-docs/adapters.md`](./agent-docs/adapters.md). Read it for NestJS, Vue
|
|
|
534
534
|
|
|
535
535
|
## 16. ESLint plugin (flat config only)
|
|
536
536
|
|
|
537
|
-
In [`agent-docs/eslint.md`](./agent-docs/eslint.md). Read it when configuring `vitest-auto-spy/eslint-plugin` or fixing one of its reports.
|
|
537
|
+
In [`agent-docs/eslint.md`](./agent-docs/eslint.md). Read it when configuring `vitest-auto-spy/eslint-plugin` or fixing one of its reports. For `vitest/require-hook`, spread `autoSpy.hookRegisteringHelpers` into `allowedFunctionCalls` rather than keeping the names by hand.
|
|
538
538
|
|
|
539
539
|
<!-- agents-outline: agent-docs/eslint.md -->
|
|
540
540
|
<!-- /agents-outline -->
|
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,82 @@ The latest released version here must always match the one published on
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [5.48.0] - 2026-09-28
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **`hookRegisteringHelpers` on `vitest-auto-spy/eslint-plugin`** — the frozen list of the
|
|
18
|
+
library's public helpers that register `beforeEach` / `afterEach` / `beforeAll` / `afterAll` when
|
|
19
|
+
called (`useConsoleSpies`, `setupAutoSpy`, `setupFakeTimers`, `useCountingClock`, `mockNow`, the
|
|
20
|
+
`guard*` family, …), for `vitest/require-hook`'s `allowedFunctionCalls`:
|
|
21
|
+
`allowedFunctionCalls: [...autoSpy.hookRegisteringHelpers]`. A bare `useConsoleSpies();` in a
|
|
22
|
+
`describe` body no longer needs a hand-kept list; a spec walks the call graph of every public entry
|
|
23
|
+
and fails when a hook-registering export is missing from it. It is a property of the plugin
|
|
24
|
+
object, so `require()` and `import` both reach it. `vitest-auto-spy/eslint-plugin` is +0.42 kB
|
|
25
|
+
min+gzip (+1.0 %) for the list and the two rule changes.
|
|
26
|
+
- **`prefer-to-have-signal-value`** also reports `expect(sig()).toBeNull()` and `.toBeUndefined()`
|
|
27
|
+
on a signal read, `.not` included, and fixes them to `toHaveSignalValue(null)` /
|
|
28
|
+
`toHaveSignalValue(undefined)`.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- **`prefer-to-have-signal-value`** no longer rewrites an identity check. `expect(list.items()).toBe(items)`
|
|
33
|
+
asserts the signal holds that very array, and the fix turned it into `toHaveSignalValue(items)`,
|
|
34
|
+
which compares deeply and passes for any equal copy. A `toBe` is now reported only when the
|
|
35
|
+
expected value is a primitive literal or the signal's type is primitive (`any` does not count);
|
|
36
|
+
`toEqual` and `toStrictEqual` are unchanged.
|
|
37
|
+
- **Docs**: `vitest-auto-spy/console` imports `vitest` itself (the fallback adapter and the
|
|
38
|
+
`useConsoleSpies()` hooks), so on `node:test` and Rstest it loads only where the `vitest` package
|
|
39
|
+
resolves; the console page, the README and `agent-docs/adapters.md` now say so. The README API
|
|
40
|
+
table and `agent-docs/angular.md` list `registerSignalMatchers({ strict })`, and the types list of
|
|
41
|
+
`/angular/matchers` names `RegisterSignalMatchersOptions`.
|
|
42
|
+
|
|
43
|
+
## [5.47.0] - 2026-09-28
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
|
|
47
|
+
- **`prefer-to-have-signal-value`** (ESLint plugin, `warn`, type-aware, autofix) rewrites
|
|
48
|
+
`expect(component.total()).toBe(3)` into `expect(component.total).toHaveSignalValue(3)`:
|
|
49
|
+
the matcher keeps the signal's name in the failure output and refuses a value that is not a
|
|
50
|
+
signal. `toEqual` maps the same way, `toStrictEqual` keeps its comparison through
|
|
51
|
+
`{ strict: true }`. The signal is recognised by its type — callable and branded with Angular's
|
|
52
|
+
signal brand, spelled `__@SIGNAL@…` by the checker — so methods, plain functions and getters stay
|
|
53
|
+
unreported, and without parser services the rule says nothing. Safe to autofix since 5.46.0, which
|
|
54
|
+
made `toHaveSignalValue` compare nested `Set` and `Map` values.
|
|
55
|
+
- **`registerSignalMatchers({ strict: true })`** flips the default of one registration: every
|
|
56
|
+
`toHaveSignalValue` of the suite compares like `toStrictEqual` without repeating the option per
|
|
57
|
+
assertion, and a single assertion can still pass `{ strict: false }`.
|
|
58
|
+
- **`expectUnhandledObservableErrors([...])` from `vitest-auto-spy/setup`** asserts the rxjs errors
|
|
59
|
+
nothing handled are exactly the ones a test deliberately left — each expected entry the error
|
|
60
|
+
itself, its class, or a message (a string or a pattern), compared in order — and hands the
|
|
61
|
+
flushed entries back. Zero-argument form asserts none were left.
|
|
62
|
+
- **`prepareShallow(Component, options).create(overrides)` from `vitest-auto-spy/angular`** binds a
|
|
63
|
+
component and the options every test of a suite repeats; `create()` runs the `renderShallow`
|
|
64
|
+
sequence with the overrides applied per key — `inputs` for an `it.each`, `providers` for a
|
|
65
|
+
one-off. One instance per test: the runner resets the TestBed between tests, and two `create()`
|
|
66
|
+
calls inside a single test need a manual `TestBed.resetTestingModule()`.
|
|
67
|
+
- **`useConsoleSpies()` from `vitest-auto-spy/console`** registers `beforeEach(installConsoleSpies)`
|
|
68
|
+
and `afterEach(restoreConsole)` in the enclosing `describe` and returns the spies, replacing the
|
|
69
|
+
hook pair every console-asserting spec wrote by hand. It registers Vitest hooks (Bun resolves them
|
|
70
|
+
to its own); on `node:test` and Rstest the pair stays manual. `no-import-time-console-spies`
|
|
71
|
+
accepts it as the file's install, and the stray-console report and docs recommend it.
|
|
72
|
+
|
|
73
|
+
### Fixed
|
|
74
|
+
|
|
75
|
+
- **An app error in `expectRequest` / `expectNoRequest`'s tick under `provideDocumentDouble()` is no
|
|
76
|
+
longer blamed on the double.** 5.46.0 rewrapped every tick failure whenever `DOCUMENT` was not the
|
|
77
|
+
real document, so an effect that threw under the library's own double read as "a partial double
|
|
78
|
+
does not have" the members Angular reads, and pointed at `{ tick: false }`, which hides the error.
|
|
79
|
+
The message is now kept for a `DOCUMENT` that is not a document, or whose `body` has no
|
|
80
|
+
`querySelector`; any other failure is rethrown as it is.
|
|
81
|
+
|
|
82
|
+
### Documentation
|
|
83
|
+
|
|
84
|
+
- **`provideDocumentDouble()` needs no `{ tick: false }`**, and a JSON error body is
|
|
85
|
+
`flush(body, { status })` — `.error(status, { error })` takes a `ProgressEvent`, as Angular's
|
|
86
|
+
`TestRequest.error()` does. The HTTP page, `agent-docs/angular.md` and `agent-docs/errors.md` say so.
|
|
87
|
+
- **The README's `SubjectLike` member list gains `unsubscribe`**, as `agent-docs` did in 5.46.0.
|
|
88
|
+
|
|
13
89
|
## [5.46.0] - 2026-09-27
|
|
14
90
|
|
|
15
91
|
### Added
|
|
@@ -6000,7 +6076,9 @@ moved under 1 %: `/angular` +192 B (+1.0 %) for the override queue and the HTTP
|
|
|
6000
6076
|
This copy ships with the package and carries 5.x only. Releases before 5.0.0 are in the
|
|
6001
6077
|
[full changelog](https://github.com/ASDAlexey/vitest-auto-spy/blob/master/CHANGELOG.md).
|
|
6002
6078
|
|
|
6003
|
-
[Unreleased]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.
|
|
6079
|
+
[Unreleased]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.48.0...HEAD
|
|
6080
|
+
[5.48.0]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.47.0...v5.48.0
|
|
6081
|
+
[5.47.0]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.46.0...v5.47.0
|
|
6004
6082
|
[5.46.0]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.45.0...v5.46.0
|
|
6005
6083
|
[5.45.0]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.44.0...v5.45.0
|
|
6006
6084
|
[5.44.0]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.43.0...v5.44.0
|
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ faster at suite scale ([benchmarks](#benchmarks)) — and for
|
|
|
81
81
|
- 🧩 Module mocks that prove they applied — `assertMocked`, `moduleNamespace`, for a `vi.mock()` a bundler quietly ignored; `moduleNamespace(await importOriginal(), { passthrough: true })` is Vitest's `{ spy: true }` with `calledWith` on top, on any runner
|
|
82
82
|
- 🧾 Fixtures without casts — deep-partial `createMock`, `createFixture` / `createFixtureFactory`, `narrow()`, `withOverrides()`, `asInstances()`, `captureArg()`, and `outOfType()` for the fixture that is outside its type on purpose
|
|
83
83
|
- 🚚 A migration you can verify — `vitest-auto-spy/diagnostics`: `compareTestRuns` on the two JSON reports, `summarizeTestRun` / `formatTestRunComparison` to read the answer, `diffByField` for the assertion the reporter collapses, `explainSpy` for a double that answered something you did not configure
|
|
84
|
-
- 📏 Lint rules and one-line test-run hygiene —
|
|
84
|
+
- 📏 Lint rules and one-line test-run hygiene — fifty rules in `vitest-auto-spy/eslint-plugin` (eight `--fix`, nineteen suggestions, four of them for a suite mid-migration off jasmine), `setupAutoSpy()` — with `preset: 'strict'` for every guard at its strictest grade, and under `isolate: false` `strayListeners` / `restoreGlobals` for the listeners and raw global assignments a file leaves the next one, `restoreStorageSpies` (on by default) for the storage spy happy-dom will not let `mockRestore()` remove
|
|
85
85
|
- 🩺 [Editor diagnostics](#editor-diagnostics--webstorm--vs-code) — the same anti-patterns underlined while you type: native ESLint inspections in **WebStorm** and the other JetBrains IDEs, the ESLint extension in **VS Code**, no extra plugin either way
|
|
86
86
|
- 🔎 [`npx vitest-auto-spy doctor`](#the-cli--doctor-perf-codemod-init-and-ng-test) — suite-level defects **that never fail a run**: a `tsconfig` `include` matching no file, a production module importing a spec, a `@jest-environment` pragma the runner never reads, config left behind for a runner that is gone. Read-only, no config, exits 1 in CI
|
|
87
87
|
- ⏱️ [`npx vitest-auto-spy perf`](#perf--where-the-cpu-time-actually-goes) — where a suite's CPU time actually goes, phase by phase, and which spec files to act on: the ones that reach no DOM and could run under `node`, the ones that import a barrel. Runs Vitest once with a reporter this package ships, reads `TestModule.diagnostic()`, names files, states the rule behind each finding
|
|
@@ -876,24 +876,23 @@ since those statuses carry no body.
|
|
|
876
876
|
A test that expects output absorbs it, and asserts on it:
|
|
877
877
|
|
|
878
878
|
```ts
|
|
879
|
-
import {
|
|
879
|
+
import { useConsoleSpies } from 'vitest-auto-spy/console';
|
|
880
880
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
beforeEach(() => {
|
|
884
|
-
consoleSpies = installConsoleSpies();
|
|
885
|
-
});
|
|
886
|
-
|
|
887
|
-
afterEach(() => restoreConsole());
|
|
881
|
+
const { consoleErrorSpy } = useConsoleSpies();
|
|
888
882
|
|
|
889
883
|
it('reports a failed load', () => {
|
|
890
884
|
service.load();
|
|
891
885
|
|
|
892
|
-
expect(
|
|
886
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('load failed', expect.any(Error));
|
|
893
887
|
});
|
|
894
888
|
```
|
|
895
889
|
|
|
896
|
-
|
|
890
|
+
`useConsoleSpies()` registers `beforeEach(installConsoleSpies)` and `afterEach(restoreConsole)` in
|
|
891
|
+
the enclosing `describe` (or the file) and returns the spies, which are the same objects in every
|
|
892
|
+
test. It registers Vitest hooks, which Bun resolves to its own; on `node:test` and Rstest write that
|
|
893
|
+
pair in the runner's hooks yourself — the entry imports `vitest` itself, so there it loads only where
|
|
894
|
+
the `vitest` package resolves. Under `vitest/require-hook`, spread `autoSpy.hookRegisteringHelpers`
|
|
895
|
+
from `vitest-auto-spy/eslint-plugin` into its `allowedFunctionCalls`. Do not
|
|
897
896
|
rely on the **import** to install them: it does so once per worker, so under `isolate: false` the
|
|
898
897
|
spies go on in whichever file imported them first and silence every later file of the worker — on a
|
|
899
898
|
1759-file Angular consumer, 32 of the 39 files importing the entry relied on that, and three files
|
|
@@ -2531,7 +2530,7 @@ subject.next([{ name: 'manual' }]);
|
|
|
2531
2530
|
|
|
2532
2531
|
`returnSubject()` and `nextWithPerCall()` are typed `SubjectOf<T>`: rxjs's own `Subject<T>` wherever
|
|
2533
2532
|
`import 'vitest-auto-spy/rxjs'` is in the TypeScript program, and the structural `SubjectLike<T>`
|
|
2534
|
-
(`next` / `error` / `complete` / `asObservable` / `closed`) where it is not. That is how the
|
|
2533
|
+
(`next` / `error` / `complete` / `unsubscribe` / `asObservable` / `closed`) where it is not. That is how the
|
|
2535
2534
|
published declarations name no rxjs type while a suite that has rxjs keeps the exact type it had.
|
|
2536
2535
|
The seam is one augmentable interface, `AutoSpyRxjsTypes<T>`, which the `/rxjs` entry fills in; what
|
|
2537
2536
|
decides that a member _is_ an observable is the other new type, `ObservableLike<T>` — `subscribe`
|
|
@@ -2945,6 +2944,20 @@ function. The matcher reads it, deep-compares (as `toEqual` does; `{ strict: tru
|
|
|
2945
2944
|
`toStrictEqual` does), and rejects anything that is not a zero-argument getter, so the
|
|
2946
2945
|
missing-parentheses mistake fails instead of quietly passing.
|
|
2947
2946
|
|
|
2947
|
+
A suite that wants the strict comparison everywhere passes it once instead of per assertion;
|
|
2948
|
+
a single assertion can still opt back out:
|
|
2949
|
+
|
|
2950
|
+
```ts
|
|
2951
|
+
registerSignalMatchers({ strict: true });
|
|
2952
|
+
|
|
2953
|
+
expect(component.items).toHaveSignalValue(items); // compares like toStrictEqual
|
|
2954
|
+
expect(component.draft).toHaveSignalValue({}, { strict: false });
|
|
2955
|
+
```
|
|
2956
|
+
|
|
2957
|
+
The `prefer-to-have-signal-value` lint rule rewrites the inline spellings — `expect(component.total()).toBe(3)`
|
|
2958
|
+
— into the matcher with a `--fix`. A `toBe` against an object-typed signal checks identity, which the
|
|
2959
|
+
deep matcher cannot keep, so the rule leaves it alone.
|
|
2960
|
+
|
|
2948
2961
|
#### Where a spec spends its time
|
|
2949
2962
|
|
|
2950
2963
|
```ts
|
|
@@ -3141,7 +3154,7 @@ and `flush()` / `error()` settle before they resolve, which is why the value rea
|
|
|
3141
3154
|
Match by URL (either `url` or `urlWithParams`), by `RegExp`, or by a predicate over the request, with
|
|
3142
3155
|
`{ method }` to tell a read from a write. `error(0)` is a network failure, and
|
|
3143
3156
|
`error(status, { error })` sets the payload the `HttpErrorResponse` carries. `{ tick: false }` skips
|
|
3144
|
-
the tick, for a module whose partial `DOCUMENT` double the tick cannot run against. `provideHttpTesting()` fails, by default, any test that
|
|
3157
|
+
the tick, for a module whose partial `DOCUMENT` double the tick cannot run against (`provideDocumentDouble()` is not partial). `provideHttpTesting()` fails, by default, any test that
|
|
3145
3158
|
ends holding a request nothing answered; `provideHttpTesting({ verifyOnTeardown: false })` turns that
|
|
3146
3159
|
off, and `verifyNoPendingRequests()` runs the same check by hand. An interceptor under test goes in
|
|
3147
3160
|
the same spread — `provideHttpTesting({ interceptors: [authInterceptor] })`, or
|
|
@@ -3342,6 +3355,7 @@ single-purpose utility you can pick up independently — they all ride on the sa
|
|
|
3342
3355
|
| `withoutStrayTimerTracking(work)` | `/setup` | Run setup work whose timers the stray-timer tracker neither counts nor cancels — jsdom schedules one per Web Storage write |
|
|
3343
3356
|
| `describeStrayTimers()` | `/setup` | Every timer still pending, with its kind and delay, the spec file that scheduled it and the scheduling frames — the list `onStrayTimers` gets. Blind to anything scheduled under fake timers — `vi.useFakeTimers()` assigns over the wrapper |
|
|
3344
3357
|
| `flushUnhandledObservableErrors()` | `/setup` | Run rxjs's pending rethrows of Observable errors nothing handled, now, and return `{ error, test }` (or `outsideTest`) for each — the check `strayTimers` runs after every test, which fails the test with `Unhandled Observable error` |
|
|
3358
|
+
| `expectUnhandledObservableErrors(expected?)` | `/setup` | The same flush as an assertion: the errors nothing handled must be exactly the ones listed — each entry the error itself, its class, or a message (string or pattern) — or the test fails with the diff; no argument asserts none were left |
|
|
3345
3359
|
| `guardPrototypePollution(reaction)` | `/setup` | Name the test that left a key on `Object.prototype` — it stops later files collecting ([details](#test-run-hygiene)) |
|
|
3346
3360
|
| `guardDocumentPollution(option)` | `/setup` | Name the test that left an attribute on `<html>` / `<body>`, and put it back ([details](#test-run-hygiene)) |
|
|
3347
3361
|
| `installPerTest(install)` | `/setup` | Re-install a stub before every test of the block — a `describe`-level stub is restored away after the first |
|
|
@@ -3377,15 +3391,14 @@ onSave.calledWith(1).resolveWith();
|
|
|
3377
3391
|
`installConsoleSpies()` replaces `console.debug` / `error` / `info` / `log` / `time` / `timeEnd` /
|
|
3378
3392
|
`trace` / `warn` with **silent, fully-typed spies**, and the entry exports each one ready to assert —
|
|
3379
3393
|
no `vi.spyOn(console, 'info')` boilerplate in every suite, no log output polluting the test run.
|
|
3380
|
-
|
|
3381
|
-
[How to mock: the console](#how-to-mock-the-console)); importing the entry installs them too, but
|
|
3382
|
-
once per worker, which under `isolate: false` silences every later file:
|
|
3394
|
+
`useConsoleSpies()` installs them before each test of the block and restores the console after
|
|
3395
|
+
(see [How to mock: the console](#how-to-mock-the-console)); importing the entry installs them too, but
|
|
3396
|
+
only once per worker, which under `isolate: false` silences every later file:
|
|
3383
3397
|
|
|
3384
3398
|
```ts
|
|
3385
|
-
import { consoleInfoSpy, consoleWarnSpy,
|
|
3399
|
+
import { consoleInfoSpy, consoleWarnSpy, useConsoleSpies } from 'vitest-auto-spy/console';
|
|
3386
3400
|
|
|
3387
|
-
|
|
3388
|
-
afterEach(() => restoreConsole());
|
|
3401
|
+
useConsoleSpies();
|
|
3389
3402
|
|
|
3390
3403
|
service.doWork();
|
|
3391
3404
|
|
|
@@ -3405,8 +3418,8 @@ the worker and every log from then on went nowhere.
|
|
|
3405
3418
|
|
|
3406
3419
|
Under `setupAutoSpy({ strayConsole })` importing the entry **installs nothing**: under
|
|
3407
3420
|
`isolate: false` the import ran once per worker and left the spies silencing every later file, which
|
|
3408
|
-
is exactly the output the guard exists to see. Call `
|
|
3409
|
-
each test
|
|
3421
|
+
is exactly the output the guard exists to see. Call `useConsoleSpies()` (or `installConsoleSpies()` in
|
|
3422
|
+
a `beforeEach`) for each test, or `installConsoleSpies()` at the top of the spec file for the file; the guard takes them off again when that
|
|
3410
3423
|
scope ends. See [How to mock: the console](#how-to-mock-the-console).
|
|
3411
3424
|
|
|
3412
3425
|
> The spies use the registered `MockAdapter` — import your runtime entry
|
|
@@ -4007,6 +4020,7 @@ export can never be.
|
|
|
4007
4020
|
| `no-import-time-spread` | `error` | suggest | `export const x = [...Imported]` at module scope → a `TypeError`, or a silently empty object, while the bundle loads |
|
|
4008
4021
|
| `no-unregistered-inject-spy` | `error` | — | `injectSpy(X)` for a token this file never registered → the real instance, whose spy helpers exist only for the compiler |
|
|
4009
4022
|
| `prefer-render-shallow` | `warn` | suggest | `TestBed.createComponent` in a file that never reads the template → `renderShallow(X)`; 0.24× the per-test cycle at 100 children |
|
|
4023
|
+
| `prefer-to-have-signal-value` | `warn` | `--fix` | `expect(signal()).toBe(…)` → `expect(signal).toHaveSignalValue(…)`; the matcher names the signal in the failure and refuses a non-signal. `toStrictEqual` keeps `{ strict: true }`, `toBeNull()` / `toBeUndefined()` become `toHaveSignalValue(null)` / `(undefined)`. **Type-aware** — the callee must be callable and carry Angular's signal brand — and silent without `parserOptions.project`; safe to autofix since 5.46.0 fixed the `Set`/`Map` comparison. A `toBe` against an object-typed signal is an identity check and is left alone |
|
|
4010
4024
|
| `prefer-set-inputs` | `warn` | suggest | a run of `fixture.componentRef.setInput('title', v)` on one fixture → `await setInputs(fixture, { title: v })`, which resolves every name against the compiled definition before it writes one — an undeclared name is an `NG0303` on the console and no change at all — and types the value. The suggestion collapses the run, drops a `detectChanges()` under it and makes the callback `async`; it is offered rather than applied, because `stable()` ticks and a zone.js suite can answer that with `NG0101` |
|
|
4011
4025
|
| `prefer-spy-on-own-method` | `warn` | `--fix` / suggest | `createSpyFromInstance(x, { onlyMethodsToSpyOn: ['m'], passthrough: true })` read for `m` alone — `.m` on the call, `const { m } = …`, a bare statement, or a name read only as `v.m` → `spyOnOwnMethod(x, 'm')`; the same whitelist with `returns: { m: undefined }` → `spyOnVoidMethod(x, 'm')`. Both fix, import and all; a `Spy<X>` annotation becomes `Spy<X>['m']` in a suggestion. A bare `returns: { m: undefined }` seed is a suggestion, offered only on a real event or element — `new MouseEvent(…)`, `document.createElement(…)`, `fixture.nativeElement` — never on a double |
|
|
4012
4026
|
| `prefer-observer-stub` | `error` | — | a hand-rolled `IntersectionObserver` / `ResizeObserver` / `MutationObserver` written into a global → `stubIntersectionObserver()` and friends, whose undo `restoreMockedProps()` already runs |
|
|
@@ -4015,7 +4029,7 @@ export can never be.
|
|
|
4015
4029
|
| `prefer-provide-activated-route` | `error` | — | a hand-built `ActivatedRoute` — any `useValue` / `useClass` / `useFactory`, and `provideAutoSpy(ActivatedRoute)` too → `provideActivatedRoute({ … })`; the double knows either the streams or the snapshot, never both, and `injectActivatedRoute().setParams(…)` moves them together mid-test |
|
|
4016
4030
|
| `no-passthrough-console-spy` | `error` | suggest | `vi.spyOn(console, m)` nothing gives an implementation — it calls through and still prints → `installConsoleSpies()` from `vitest-auto-spy/console`, or `.mockImplementation(() => undefined)` |
|
|
4017
4031
|
| `no-console-in-spec` | `error` | — | a spec that calls `console.x(…)` itself, or replaces a method with `console.x = …`, which nothing puts back — under `isolate: false` every later file inherits it |
|
|
4018
|
-
| `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, under `isolate: false`, silences every later file
|
|
4032
|
+
| `no-import-time-console-spies` | `error` | — | an import of `vitest-auto-spy/console` in a file that never calls `installConsoleSpies()` or `useConsoleSpies()` — the import installs once per worker and, under `isolate: false`, silences every later file |
|
|
4019
4033
|
| `no-mistyped-use-value` | `error` | — | `{ provide: TOKEN, useValue }` whose value is not assignable to the primitive `TOKEN` declares — `useValue` is `any`, so `{}` for an `InjectionToken<boolean>` compiles and is truthy; **type-aware**, and silent without `parserOptions.project` |
|
|
4020
4034
|
| `no-unknown-use-value-key` | `error` | — | a key of an object `useValue` literal the provided type does not have — `T` of an `InjectionToken<T>`, or a class's instance; keys only, never the values; silent on `any` / `unknown`, an index signature, a spread and `multi: true`; **type-aware** |
|
|
4021
4035
|
| `no-instance-lifecycle-spy` | `warn` | — | `vi.spyOn(component, 'ngOnInit')` and the other hooks a view reads off the prototype — Angular never calls the instance spy → spy on `Cls.prototype` before the component is created, or assert the hook's effect |
|
|
@@ -4040,7 +4054,7 @@ Every message ends with a link to the matching [recipe](#how-to-mock): a rule th
|
|
|
4040
4054
|
"don't" moves the problem rather than solving it. Rules travel with the API they recommend, so they
|
|
4041
4055
|
are versioned together and stop being re-written in every project that installs the package.
|
|
4042
4056
|
|
|
4043
|
-
**
|
|
4057
|
+
**Eight of the fifty fix on their own, nineteen offer suggestions**, and the split is not about how hard
|
|
4044
4058
|
the rewrite is. `no-mocked-for-spy` touches a _declaration_: get it wrong and the file stops
|
|
4045
4059
|
compiling, which is the loudest, cheapest failure there is — so `--fix` rewrites the type, adds
|
|
4046
4060
|
`import type { Spy } from 'vitest-auto-spy'` and drops the `Mocked` import once nothing else uses
|
|
@@ -4211,7 +4225,7 @@ package's own — it needs its ESLint integration switched on.
|
|
|
4211
4225
|
### WebStorm and the other JetBrains IDEs
|
|
4212
4226
|
|
|
4213
4227
|
No plugin to install: WebStorm, IntelliJ IDEA Ultimate, PhpStorm, PyCharm Professional and RubyMine
|
|
4214
|
-
all run ESLint natively, so the
|
|
4228
|
+
all run ESLint natively, so the fifty rules appear inline, in the **Problems** tool window, and
|
|
4215
4229
|
under **Code → Inspect Code** for the whole project.
|
|
4216
4230
|
|
|
4217
4231
|
```js
|
|
@@ -4228,7 +4242,7 @@ has supported flat config since 2023.3); scope the block to spec files yourself;
|
|
|
4228
4242
|
the fixes and suggestions live.
|
|
4229
4243
|
|
|
4230
4244
|
A native JetBrains plugin is **not** planned — it would duplicate an integration the IDE already has
|
|
4231
|
-
and then keep a second copy of
|
|
4245
|
+
and then keep a second copy of fifty rules, in Kotlin, in step with the TypeScript ones.
|
|
4232
4246
|
|
|
4233
4247
|
### VS Code, Cursor, Windsurf, VSCodium
|
|
4234
4248
|
|
|
@@ -4334,6 +4348,7 @@ another, and the next one is in that same file.
|
|
|
4334
4348
|
| `setupFakeTimers(config?)` / `advanceTimers(ms?)` _(`/setup`)_ | Paired fake-timer install/restore, and an advance that also settles queued microtasks |
|
|
4335
4349
|
| `describeDuplicateCopies()` / `getPackageCopies()` | The duplicate-install report, and the copies behind it |
|
|
4336
4350
|
| `renderShallow(Component, opts?)` _(Angular)_ | `TestBed` component, minus its children and (by default) its template |
|
|
4351
|
+
| `prepareShallow(Component, opts?)` _(Angular)_ | `renderShallow` bound to shared options — `.create(overrides?)` per test, one instance each |
|
|
4337
4352
|
| `setInputs(fixture, inputs, opts?)` _(Angular)_ | Change an input after the first render — one `setInput` per name, checked against the compiled definition, then one wait |
|
|
4338
4353
|
| `createWithAutoSpies(Class, opts?)` _(Angular)_ | Build a class through Angular DI with every unprovided token auto-spied |
|
|
4339
4354
|
| `createNestUnit(Class, opts?)` _(NestJS)_ | Build a provider from its DI metadata with every unprovided token auto-spied; `expose` builds collaborators for real, `providers` wins over both |
|
|
@@ -4348,7 +4363,7 @@ another, and the next one is in that same file.
|
|
|
4348
4363
|
| `collectRouterEvents(events)` _(`/angular-router`)_ | The double's router events as one comparable value — `expect([[NavigationStart, '/checkout'], …])`, a class-and-URL pair per event |
|
|
4349
4364
|
| `provideLocationDouble()` / `injectLocationDouble(injector?)` / `createLocationDouble()` _(`/angular-router`)_ | Angular's own `SpyLocation` and `MockLocationStrategy` in one call — a real history, the `urlChanges` journal, `simulateUrlPop()` for the popstate no method call can cause |
|
|
4350
4365
|
| `createForm(model, schema?, options?)` / `registerFormMatchers()` _(`/signal-forms`)_ | Angular's own signal `form()`, built in the `TestBed`'s injection context, and the `toHaveFieldErrors` matcher over its `errors()` |
|
|
4351
|
-
| `registerSignalMatchers()` _(Angular)_
|
|
4366
|
+
| `registerSignalMatchers(opts?)` _(Angular)_ | Adds `expect(sig).toHaveSignalValue(value)`; `{ strict: true }` compares every assertion like `toStrictEqual` |
|
|
4352
4367
|
| `trackRecomputations(signal)` / `trackEffectRuns(effectRef)` _(Angular)_ | Count what the reactive graph re-ran — `{ count, stop() }`, undone by `restoreMockedProps()` |
|
|
4353
4368
|
| `provideWindowDouble(token, overrides?)` / `provideDocumentDouble(overrides?)` _(Angular)_ | A `window` / `document` merged over the real jsdom one; `createWindowDouble` / `createDocumentDouble` outside DI |
|
|
4354
4369
|
| `provideMatDialogData(token, data)` / `provideMatDialogRef(Ref, init?)` / `injectMatDialogRef(Ref)` _(Angular)_ | The Material dialog trio — the token and the ref class are arguments; `createMatDialogRef` builds the ref outside DI |
|
|
@@ -4366,6 +4381,7 @@ another, and the next one is in that same file.
|
|
|
4366
4381
|
| `guardDocumentPollution(option)` _(`/setup`)_ | Name the test that left an attribute on `<html>` / `<body>`, before a later file takes another branch on it |
|
|
4367
4382
|
| `consoleDebugSpy` … `consoleWarnSpy` _(`/console`)_ | Silent typed spies replacing the global `console` methods on import |
|
|
4368
4383
|
| `installConsoleSpies()` / `resetConsoleSpies()` / `restoreConsole()` | Install / clear / undo the console spies |
|
|
4384
|
+
| `useConsoleSpies()` _(`/console`)_ | Install the console spies before each test of the block, restore after; returns the spies |
|
|
4369
4385
|
| `consoleOutput()` _(`/console`)_ | Everything the console spies recorded, keyed by channel, only the channels written to — `toStrictEqual({})` is silence |
|
|
4370
4386
|
| `explainSpy(spy, method?)` _(`/diagnostics`)_ | Every configured argument list next to every recorded call, attributed to the config it hit |
|
|
4371
4387
|
| `errorHandler` | The `mustBeCalledWith` argument-mismatch error helper |
|
package/agent-docs/adapters.md
CHANGED
|
@@ -28,21 +28,21 @@ import { createSpyFromClass } from 'vitest-auto-spy/react';
|
|
|
28
28
|
|
|
29
29
|
Console spies — `installConsoleSpies()` replaces `console.debug` / `error` / `info` / `log` / `time` /
|
|
30
30
|
`timeEnd` / `trace` / `warn` with silent typed spies, named `console<Method>Spy`. Install them per test
|
|
31
|
-
and take them off after it
|
|
31
|
+
and take them off after it — `useConsoleSpies()` registers exactly that pair in the enclosing `describe`:
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
import {
|
|
34
|
+
import { useConsoleSpies } from 'vitest-auto-spy/console';
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const { consoleInfoSpy } = useConsoleSpies();
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
consoleSpies = installConsoleSpies();
|
|
40
|
-
});
|
|
41
|
-
afterEach(() => restoreConsole());
|
|
42
|
-
|
|
43
|
-
expect(consoleSpies.consoleInfoSpy).toHaveBeenCalledWith('done'); // the output is silenced, not printed
|
|
38
|
+
expect(consoleInfoSpy).toHaveBeenCalledWith('done'); // the output is silenced, not printed
|
|
44
39
|
```
|
|
45
40
|
|
|
41
|
+
It registers Vitest hooks (Bun resolves them to its own); on `node:test` and Rstest write
|
|
42
|
+
`installConsoleSpies()` in a `beforeEach` and `restoreConsole()` in an `afterEach` yourself. The entry
|
|
43
|
+
imports `vitest` itself, so there it loads only where the `vitest` package resolves. Under
|
|
44
|
+
`vitest/require-hook`, spread `autoSpy.hookRegisteringHelpers` into `allowedFunctionCalls` (§16).
|
|
45
|
+
|
|
46
46
|
The exported `consoleInfoSpy` & co. are the same objects; `restoreConsole()` keeps them and clears
|
|
47
47
|
their calls. **Do not rely on the import to install them**: it does so once per worker, so under
|
|
48
48
|
`isolate: false` the spies go on in whichever file imported them first and silence every later file
|
package/agent-docs/angular.md
CHANGED
|
@@ -203,7 +203,10 @@ replaced where nothing would notice it — the refusal now names `computed()` sp
|
|
|
203
203
|
that driving the signal the computation reads is the way through. An `input()` is refused outright:
|
|
204
204
|
Angular sets an input through the input node rather than the property, so a replaced one breaks the
|
|
205
205
|
host's next write. Drive an input with `await setInputs(fixture, { … })`, or with
|
|
206
|
-
`renderShallow(Component, { inputs: { … } })` for the value it starts at.
|
|
206
|
+
`renderShallow(Component, { inputs: { … } })` for the value it starts at. When every test of a
|
|
207
|
+
describe renders the same component with the same providers, `prepareShallow(Component, opts)` binds
|
|
208
|
+
them once and each test calls `.create({ inputs: { … } })` — the overrides replace a key outright,
|
|
209
|
+
one instance per test.
|
|
207
210
|
|
|
208
211
|
### Observers the component constructs itself
|
|
209
212
|
|
|
@@ -511,6 +514,8 @@ provided after it, so it wins over `withXhr()`.
|
|
|
511
514
|
carries (default `new ProgressEvent('error')`). A module that provides a partial `DOCUMENT` double
|
|
512
515
|
fails Angular's tick (`inject(...).body?.querySelector is not a function`, reported as a doubled
|
|
513
516
|
`DOCUMENT`): pass `{ tick: false }` to `expectRequest` / `expectNoRequest` when the request is already out.
|
|
517
|
+
`provideDocumentDouble()` is not partial and needs no option. A JSON error body is a response:
|
|
518
|
+
`flush(body, { status: 409 })`; `{ error }` on `.error()` is a `ProgressEvent`.
|
|
514
519
|
`flush()` and `error()` are `async` because settling requires letting a microtask run — `await` them,
|
|
515
520
|
and the next line reads the settled value.
|
|
516
521
|
|
|
@@ -1058,8 +1063,8 @@ service.products.set([edited]); // the component's own optimistic write — stat
|
|
|
1058
1063
|
expect(products.reload).toHaveBeenCalled(); // reload is spied, answers true, and re-issues nothing
|
|
1059
1064
|
|
|
1060
1065
|
// signal assertions
|
|
1061
|
-
registerSignalMatchers(); // once, in the setup file — /angular/matchers
|
|
1062
|
-
expect(component.total).toHaveSignalValue(3); // toEqual semantics; { strict: true } for toStrictEqual's
|
|
1066
|
+
registerSignalMatchers(); // once, in the setup file — /angular/matchers; ({ strict: true }) makes the whole suite strict
|
|
1067
|
+
expect(component.total).toHaveSignalValue(3); // toEqual semantics; { strict: true } for toStrictEqual's, { strict: false } opts out
|
|
1063
1068
|
|
|
1064
1069
|
// resource assertions — value AND status, which is the whole point
|
|
1065
1070
|
registerResourceMatchers(); // once, in the setup file — /angular/matchers
|
|
@@ -61,8 +61,9 @@ Part of the agent reference [`AGENTS.md`](../AGENTS.md), which maps every sectio
|
|
|
61
61
|
| an assertion containing a date, with no clock set | `mockSystemTime(iso)` first |
|
|
62
62
|
| `configureTestingModule` inside every `it()` | one per `describe` |
|
|
63
63
|
| `vi.mock('@angular/core')` to neutralise `effect()` | set the signals, `await stable(fixture)`, assert the result |
|
|
64
|
-
| a second `vi.spyOn(console, 'error')` | `consoleErrorSpy` from `vitest-auto-spy/console`, installed with `
|
|
65
|
-
| `import { consoleErrorSpy } from 'vitest-auto-spy/console'` as the install | `
|
|
64
|
+
| a second `vi.spyOn(console, 'error')` | `consoleErrorSpy` from `vitest-auto-spy/console`, installed with `useConsoleSpies()` |
|
|
65
|
+
| `import { consoleErrorSpy } from 'vitest-auto-spy/console'` as the install | `useConsoleSpies()` in the `describe` (the `installConsoleSpies()` / `restoreConsole()` hook pair) — the import installs once per worker |
|
|
66
|
+
| `beforeEach(installConsoleSpies)` with `afterEach(restoreConsole)` repeated per spec | `useConsoleSpies()` — registers both hooks and returns the spies |
|
|
66
67
|
| a bare `vi.spyOn(console, 'error')` to keep a spec quiet | `.mockImplementation(() => undefined)` — without it the line still prints |
|
|
67
68
|
| `mockReadonlyProp(c, 'items', vi.fn(() => []))` | `mockReadonlyProp(c, 'items', signal([]))` — a real signal |
|
|
68
69
|
| `spy.m.mockReturnValue(subject$)` for a `vi.fn(() => subject$)` | `spy.m.mockImplementation(() => subject$)` — the variable is re-read |
|
package/agent-docs/errors.md
CHANGED
|
@@ -168,7 +168,7 @@ Part of the agent reference [`AGENTS.md`](../AGENTS.md), which maps every sectio
|
|
|
168
168
|
| `expectRequest: no GET …?page=2 — but GET …?page=3 was made; the query differs` | the same path, another query string | name the query the code sends, or match the path alone: `expectRequest('/api/products')` (§13) |
|
|
169
169
|
| `expectRequest: no request matched … — nothing was requested at all` | an `httpResource()` whose `request()` returned no URL yet, or an `HttpClient` call nothing subscribed to | set the signal the resource reads, or subscribe to the call (§13) |
|
|
170
170
|
| `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) |
|
|
171
|
-
| `TestBed.tick() failed, and this TestBed provides its own DOCUMENT` (cause: `inject(...).body?.querySelector is not a function`) | `expectRequest` / `expectNoRequest` ticked the app, and Angular's tick reads members a partial `DOCUMENT` double lacks | `expectRequest(url, { tick: false })` when the request is already out (an `HttpClient` call), or provide a real document |
|
|
171
|
+
| `TestBed.tick() failed, and this TestBed provides its own DOCUMENT` (cause: `inject(...).body?.querySelector is not a function`) | `expectRequest` / `expectNoRequest` ticked the app, and Angular's tick reads members a partial `DOCUMENT` double lacks | `expectRequest(url, { tick: false })` when the request is already out (an `HttpClient` call), or provide a real document — `provideDocumentDouble()` is one: it keeps every member, and an app error under it is rethrown as it is |
|
|
172
172
|
| `X was never answered (end of "…")` / `N requests were never answered` | `provideHttpTesting({ verifyOnTeardown })` or `enableAngularDiagnostics({ pendingRequests })` — the test left a request open; the message names its URL and the test | answer it with the line the message prints (`await expectRequest(url).flush(body)`, `controller.expectOne(url).flush(body)` under diagnostics in a module built on `provideHttpClientTesting()`), or assert its absence (`expectNoRequest(url)`); a cancelled one is forgiven with the `ignoreCancelled` opt-in the message names (§13) |
|
|
173
173
|
| `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) |
|
|
174
174
|
| `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) |
|
package/agent-docs/eslint.md
CHANGED
|
@@ -32,6 +32,25 @@ blanket downgrade so those keep their severity; do not copy the two names into a
|
|
|
32
32
|
`autoSpy.configs.strict` is `recommended` with every rule at `error`, instead of mapping
|
|
33
33
|
`Object.keys(autoSpy.rules)` by hand.
|
|
34
34
|
|
|
35
|
+
`@vitest/eslint-plugin`'s `vitest/require-hook` reports a bare `useConsoleSpies();` or
|
|
36
|
+
`setupFakeTimers();` in a `describe` body, since it cannot know the call registers hooks.
|
|
37
|
+
`autoSpy.hookRegisteringHelpers` is the library's list of such helpers — every public function that
|
|
38
|
+
calls `beforeEach` / `afterEach` / `beforeAll` / `afterAll` when it runs, kept in step with the
|
|
39
|
+
source by a spec — so spread it instead of maintaining the names by hand. Calls that register no
|
|
40
|
+
hook (`registerSignalMatchers()`, `trackStrayTimers()`) are not in it; add them yourself where a
|
|
41
|
+
linted file calls them at the top level.
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
export default [
|
|
45
|
+
{
|
|
46
|
+
files: ['**/*.spec.ts'],
|
|
47
|
+
rules: {
|
|
48
|
+
'vitest/require-hook': ['error', { allowedFunctionCalls: [...autoSpy.hookRegisteringHelpers] }],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
```
|
|
53
|
+
|
|
35
54
|
| Rule | Level | Fix | Flags |
|
|
36
55
|
| --- | --- | --- | --- |
|
|
37
56
|
| `no-expect-in-subscribe` | `error` | suggest | `expect()` inside `subscribe()` → `expectEmission` / `firstValueFrom` |
|
|
@@ -56,6 +75,7 @@ blanket downgrade so those keep their severity; do not copy the two names into a
|
|
|
56
75
|
| `no-unregistered-inject-spy` | `error` | — | `injectSpy(X)` for a token this file never registered → the real instance, whose spy helpers exist only for the compiler |
|
|
57
76
|
| `prefer-render-shallow` | `warn` | suggest | `TestBed.createComponent` in a file that never reads the template → `renderShallow(X)`; 0.24× the per-test cycle at 100 children |
|
|
58
77
|
| `prefer-set-inputs` | `warn` | suggest | a run of `fixture.componentRef.setInput('title', v)` on one fixture → `await setInputs(fixture, { title: v })` — the name is resolved against the compiled definition before the first write (an undeclared one is an `NG0303` and no change) and the value is typed. The run collapses into one call and a `detectChanges()` under it goes; offered, not applied, because `stable()` ticks and a zone.js suite answers that with `NG0101` |
|
|
78
|
+
| `prefer-to-have-signal-value` | `warn` | `--fix` | `expect(component.total()).toBe(3)` / `toEqual(…)` → `expect(component.total).toHaveSignalValue(3)`, `toStrictEqual` → `{ strict: true }`, `toBeNull()` / `toBeUndefined()` → `toHaveSignalValue(null)` / `(undefined)`; the matcher names the signal in the failure and refuses a value that is not one. **Type-aware**: the signal is recognised by Angular's brand on its type, so methods, functions and getters are never reported, and without `parserOptions.project` it reports nothing. A `toBe` against an object-typed signal (`expect(list.items()).toBe(items)`) is an identity check the deep matcher would lose, so it is reported only when the expected value is a primitive literal or the signal's type is primitive |
|
|
59
79
|
| `prefer-spy-on-own-method` | `warn` | `--fix` / suggest | `createSpyFromInstance(x, { onlyMethodsToSpyOn: ['m'], passthrough: true })` read for `m` alone — `.m` on the call, `const { m } = …`, a bare statement, or a name read only as `v.m` → `spyOnOwnMethod(x, 'm')`; the same whitelist with `returns: { m: undefined }` → `spyOnVoidMethod(x, 'm')`. Both fix, import and all; a `Spy<X>` annotation becomes `Spy<X>['m']` in a suggestion. A bare `returns: { m: undefined }` seed is a suggestion, offered only on a real event or element — `new MouseEvent(…)`, `document.createElement(…)`, `fixture.nativeElement` — never on a double |
|
|
60
80
|
| `prefer-observer-stub` | `error` | — | a hand-rolled observer global → `stubIntersectionObserver()` / `stubResizeObserver()` / `stubMutationObserver()`; the manual save-and-restore goes too, `restoreMockedProps()` runs the undo |
|
|
61
81
|
| `no-hand-assigned-global` | `error` | `--fix` | a double assigned to a global (`global.fetch = vi.fn()`, `window.matchMedia = vi.fn()`, `window.localStorage = { getItem: vi.fn() }`) with no restore in `afterEach` / `afterAll` / `onTestFinished` → `mockValueProp(globalThis, name, value)` or `vi.stubGlobal` + `unstubGlobals`; `blockNetwork()` for network globals, `stubWebStorage()` for the storages, `stubWorker({ respond })` for `Worker`; the three observers stay with `prefer-observer-stub`; any value written into an imported object (`environment.production = true`) → `mockValueProp(environment, 'production', true)`, fixed in a test or `beforeEach` |
|
|
@@ -63,7 +83,7 @@ blanket downgrade so those keep their severity; do not copy the two names into a
|
|
|
63
83
|
| `prefer-provide-activated-route` | `error` | — | a hand-built `ActivatedRoute` — any `useValue` / `useClass` / `useFactory` / `useExisting`, and `provideAutoSpy(ActivatedRoute)` too → `provideActivatedRoute({ … })`; the double knows either the streams or the snapshot, never both, and `injectActivatedRoute().setParams(…)` moves them together mid-test |
|
|
64
84
|
| `no-passthrough-console-spy` | `error` | suggest | `vi.spyOn(console, m)` nothing gives an implementation — it calls through and prints → `installConsoleSpies()` + `consoleXSpy`, or `.mockImplementation(() => undefined)` |
|
|
65
85
|
| `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` |
|
|
66
|
-
| `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` |
|
|
86
|
+
| `no-import-time-console-spies` | `error` | — | an import of `vitest-auto-spy/console` in a file that never calls `installConsoleSpies()` or `useConsoleSpies()` — the import installs once per worker and silences every later file → `installConsoleSpies()` in `beforeEach`, `restoreConsole()` in `afterEach` |
|
|
67
87
|
| `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 |
|
|
68
88
|
| `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` |
|
|
69
89
|
| `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 |
|
|
@@ -84,14 +104,14 @@ blanket downgrade so those keep their severity; do not copy the two names into a
|
|
|
84
104
|
| `no-save-arguments-by-value` | `error` | — | `spy.calls.saveArgumentsByValue()` — a no-op here, so the spec silently asserts on post-mutation state |
|
|
85
105
|
| `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 |
|
|
86
106
|
|
|
87
|
-
|
|
107
|
+
Fifty rules, **every one an `error` since 4.0.0 except `prefer-render-shallow`,
|
|
88
108
|
`no-stub-class-double`, `no-structural-double`, `prefer-create-mock`, `no-instance-lifecycle-spy`,
|
|
89
|
-
`prefer-set-inputs`, `no-unasserted-argument
|
|
90
|
-
`no-unknown-use-value-key` read types, and all
|
|
109
|
+
`prefer-set-inputs`, `no-unasserted-argument`, `prefer-spy-on-own-method` and `prefer-to-have-signal-value`**; eight fix on their own, nineteen offer suggestions. Forty-six are syntactic; `no-private-member-access`, `no-mistyped-use-value`,
|
|
110
|
+
`no-unknown-use-value-key` and `prefer-to-have-signal-value` read types, and all four report nothing at all without `parserOptions.project` / `projectService`
|
|
91
111
|
rather than guessing. `no-compile-components` waits the same way for a fact no file holds — which
|
|
92
112
|
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
|
|
93
113
|
consumer how much each finding mattered — a `warn` nothing reads is `off` with extra output. The
|
|
94
|
-
|
|
114
|
+
nine `warn`s left are not judgements about how much a finding matters. `prefer-render-shallow` is
|
|
95
115
|
about the _kind_ of finding: every other rule names something wrong or dead, while this one names a
|
|
96
116
|
file that could render more cheaply, and `renderShallow` is a migration a suite either takes or does
|
|
97
117
|
not. At `error` the plugin would gate that migration — 491 findings across 398 of one consumer's
|
package/agent-docs/setup.md
CHANGED
|
@@ -94,7 +94,11 @@ nothing. Fix it where the stream is subscribed — an error callback or `catchEr
|
|
|
94
94
|
error. `flushUnhandledObservableErrors()` is the same check by hand: it returns `{ error, test }` (or
|
|
95
95
|
`{ error, outsideTest }`) for each rethrow that threw; assert the errors alone with
|
|
96
96
|
`expect(flushUnhandledObservableErrors()).toMatchObject([{ error: new Error('502') }])` — it checks the
|
|
97
|
-
count and ignores `test`, with no `.map(({ error }) => error)`.
|
|
97
|
+
count and ignores `test`, with no `.map(({ error }) => error)`. A test that deliberately leaves the
|
|
98
|
+
error unhandled asserts it in place instead: `expectUnhandledObservableErrors([{ message: /502/ }])`
|
|
99
|
+
flushes and compares — each entry the error itself, its class, or a message (a string or a pattern),
|
|
100
|
+
in order — and fails with a diff listing what was expected and what was found; no argument asserts
|
|
101
|
+
nothing was left.
|
|
98
102
|
|
|
99
103
|
**`countStrayTimers()` cannot see a timer scheduled under fake timers, and that does not compose
|
|
100
104
|
away.** `vi.useFakeTimers()` assigns its own `setTimeout` over the tracking wrapper, so everything
|
|
@@ -722,7 +726,7 @@ frame outside `node_modules`, and naming the spy that absorbs it:
|
|
|
722
726
|
[vitest-auto-spy] "CartService > reports a failed load" wrote to console.error 1 time and nothing absorbed it:
|
|
723
727
|
- console.error: Error: load failed
|
|
724
728
|
at CartService.load (src/app/cart.service.ts:41:15)
|
|
725
|
-
Absorb what the test expects —
|
|
729
|
+
Absorb what the test expects — useConsoleSpies() in the describe, then assert consoleErrorSpy — or fix the code if the output is a defect.
|
|
726
730
|
Docs: https://asdalexey.github.io/vitest-auto-spy/utilities/setup#_16-console-output-nothing-absorbed
|
|
727
731
|
```
|
|
728
732
|
|
|
@@ -748,7 +752,7 @@ Docs: https://asdalexey.github.io/vitest-auto-spy/utilities/setup#_16-console-ou
|
|
|
748
752
|
`It is reported at the end of b.spec.ts: the file-end check of a.spec.ts did not run.`
|
|
749
753
|
- Every console method a test replaced is put back after it; one a file replaced, after the file.
|
|
750
754
|
- Under the guard, **importing `vitest-auto-spy/console` installs nothing** — call
|
|
751
|
-
`
|
|
755
|
+
`useConsoleSpies()` in the `describe` (or `installConsoleSpies()` at the top of the file). Spies an import installed
|
|
752
756
|
before the guard armed are taken off.
|
|
753
757
|
- `strayConsole: { allow: ['…', /…/] }` is the last resort, for a line from a dependency no spec can
|
|
754
758
|
reach — the import-time report offers it, with the pattern, only when the quoted frame is inside
|
package/dist/angular-http.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ declare function provideHttpTesting(options?: HttpTestingOptions): (EnvironmentP
|
|
|
97
97
|
* that was never sent rather than one that was sent wrongly.
|
|
98
98
|
*
|
|
99
99
|
* @param matcher The URL, a pattern for it, or a predicate over the request.
|
|
100
|
-
* @param options `{ method }`, for a URL that is both read and written in the same test
|
|
100
|
+
* @param options `{ method }`, for a URL that is both read and written in the same test; `{ tick: false }` for a doubled `DOCUMENT`.
|
|
101
101
|
*/
|
|
102
102
|
declare function expectRequest(matcher: RequestMatcher, options?: ExpectRequestOptions): RequestExpectation;
|
|
103
103
|
/**
|
package/dist/angular-http.js
CHANGED
|
@@ -175,11 +175,22 @@ async function settle(tick) {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
+
function isPartialDocument(doc) {
|
|
179
|
+
const real = globalThis.document;
|
|
180
|
+
if (doc === real) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
if (Reflect.getPrototypeOf(Object(doc)) !== Reflect.getPrototypeOf(Object(real))) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
const body = Reflect.get(Object(doc), "body");
|
|
187
|
+
return typeof Reflect.get(Object(body), "querySelector") !== "function";
|
|
188
|
+
}
|
|
178
189
|
function tickApp(caller) {
|
|
179
190
|
try {
|
|
180
191
|
flushEffects();
|
|
181
192
|
} catch (error) {
|
|
182
|
-
if (TestBed.inject(DOCUMENT)
|
|
193
|
+
if (!isPartialDocument(TestBed.inject(DOCUMENT))) {
|
|
183
194
|
throw error;
|
|
184
195
|
}
|
|
185
196
|
throw new Error(
|