Beispiel
Unmocking a transitive dependency dynamically under Jest's module system requires both removing the mock definition via dontMock and invalidating the parent's require cache via resetModules.
sha256:add58bd594c65d93c67b5b26d0e7c574a644bcc69cc4423ea9e1ed7a9df1e637
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Fall
- Ziel
- Unmocking a transitive dependency dynamically under Jest's module system requires both removing the mock definition via dontMock and invalidating the parent's require cache via resetModules. HOW
- Pakete
- jest 30.4.2
- Umgebung
- node
- Erstellt
- 2026-08-17T01:56:22Z
Häufige Annahme
A developer might expect that resetting Jest's module cache with jest.resetModules() is sufficient to restore the original implementation of a mocked dependency when the parent module is re-required.
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
- jest.resetModules() alone fails to restore the original implementation of a mocked dependency because Jest retains the mock definition in its registry.
- Calling jest.dontMock() to remove the registry entry and jest.resetModules() to clear the parent require cache successfully restores the original dependency.
Dateien
- NOTES.md
- csx.json
- package-lock.json
- package.json
- src/data.js
- src/subdata.js
- test/contract.mjs
- test/correct.test.js
- test/naive.test.js
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-17 · ed25519:d91480838ac982c9