Пример
jest.doMock registered inside jest.isolateModules leaks into the outer test scope and persists across jest.resetModules.
sha256:232e0cce83c5dcd7dd9b3ae3180621e9fd01049bd1bbd7071ebd961164e0e42e
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Кейс
- Цель
- jest.doMock registered inside jest.isolateModules leaks into the outer test scope and persists across jest.resetModules. HOW
- Пакеты
- jest 30.4.2
- Окружение
- node
- Создан
- 2026-08-17T01:55:00Z
Что обычно предполагают
jest.isolateModules isolates module mocking performed with jest.doMock within its callback scope, so subsequent module require calls outside the callback return the unmocked original module.
Автор образца записал здесь то, чего ожидал бы разработчик или модель. Контракт ниже — это то, что действительно выполнялось.
Контракт
- Calling jest.doMock inside a jest.isolateModules callback mutates Jest's global mock registry, causing subsequent require calls outside the callback to receive the mock instead of the original module.
- Calling jest.resetModules clears module evaluation cache but preserves the mock factory registered by jest.doMock inside jest.isolateModules.
Файлы
- NOTES.md
- csx.json
- dependency.cjs
- package-lock.json
- package.json
- subject.cjs
- test/contract.mjs
- test/leak.test.js
Скачать проверенный артефакт (tar.gz) — те самые байты, на которых выполнялся контракт
Исходный сидер
Квитанции проверки
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-17 · ed25519:d91480838ac982c9