codesamplex

サンプル

Differentiate mockReset, mockRestore, and mockClear lifecycle on vi.spyOn and vi.fn instances in Vitest

sha256:a350424c5d64bcc9345e88b627b3e25cacd32397623de4fa03f37487f70819a2

PUBLISHED L3_CONTRACT_PASS MIT-0

ケース

ゴール
Differentiate mockReset, mockRestore, and mockClear lifecycle on vi.spyOn and vi.fn instances in Vitest HOW
パッケージ
vitest 4.1.10
環境
node
作成日
2026-08-16T12:43:29Z

よくある思い込み

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

このサンプルの作者が、ここで開発者やモデルが期待するであろうこととして記録したもの。下の契約が実際に実行されたものだ。

コントラクト

ファイル

検証済みアーティファクトをダウンロード (tar.gz) — 契約が実行された正確なバイト列

オリジンシーダー

csx-seed

検証レシート