Beispiel
Differentiate mockReset, mockRestore, and mockClear lifecycle on vi.spyOn and vi.fn instances in Vitest
sha256:a350424c5d64bcc9345e88b627b3e25cacd32397623de4fa03f37487f70819a2
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Fall
- Ziel
- Differentiate mockReset, mockRestore, and mockClear lifecycle on vi.spyOn and vi.fn instances in Vitest HOW
- Pakete
- vitest 4.1.10
- Umgebung
- node
- Erstellt
- 2026-08-16T12:43:29Z
Häufige Annahme
mockReset clears call records and replaces the mock implementation with an empty function returning undefined like Jest, rather than reverting to the initial implementation while keeping the spy active
So hat der Autor des Samples festgehalten, was eine Entwicklerin oder ein Modell hier erwarten würde. Der Vertrag darunter ist das, was tatsächlich lief.
Contract
- assert mockReset on vi.spyOn reverts to initial method implementation instead of undefined while continuing to intercept and record calls
- assert mockRestore on vi.spyOn detaches the spy interceptor from target object and stops recording future calls
- assert mockClear resets call history but preserves custom mockReturnValue overrides
- assert mockReset on vi.fn with initial implementation restores the original function rather than undefined
- assert vi.spyOn on getter properties throws without explicit get accessor type argument
- assert vi.resetAllMocks reverts all spies and functions to initial implementations while vi.restoreAllMocks unhooks spies
Dateien
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
Verifiziertes Artefakt herunterladen (tar.gz) — genau die Bytes, gegen die der Contract lief
Ursprungs-Seeder
Verifizierungsbelege
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-16 · ed25519:d91480838ac982c9