Пример
@vitest/spy 2.1.9: isMockFunction
Проверенный пример — npm @vitest/spy 2.1.9: isMockFunction. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден.
sha256:b89badde09e6300b99d7e0450fa69c76162ed1e58cdf6f833b134a089456c777
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 npm
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-06 |
Кейс
HOW- Цель
- verify @vitest/spy.isMockFunction in pkg:npm/%40vitest/spy@2.1.9
- Пакеты
- Символы
-
- @vitest/spy.isMockFunction
- Создан
- 2026-09-06T18:09:43Z
Контракт
- @vitest/spy.isMockFunction returns true for mock functions created with fn()
- @vitest/spy.isMockFunction returns true for spies created on object methods with spyOn()
- @vitest/spy.isMockFunction returns true for getter and setter spies created with spyOn()
- @vitest/spy.isMockFunction returns false for regular unmocked functions and async functions
- @vitest/spy.isMockFunction returns false for non-function values such as null, undefined, objects, numbers, and strings
- @vitest/spy.isMockFunction returns false for ordinary objects that mimic mock properties without being a function
- @vitest/spy.isMockFunction returns false for original methods after spy.mockRestore() is invoked
Файлы
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Исходный код
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify @vitest/spy.isMockFunction in pkg:npm/%40vitest/spy@2.1.9
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40vitest/spy@2.1.9
Demonstrate these symbols/APIs:
- @vitest/spy.isMockFunction
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:1615857ec2170fe17228907df74d3044e3efdaf6851b05fb7b10013326cabc6f","contract":["@vitest/spy.isMockFunction returns true for mock functions created with fn()","@vitest/spy.isMockFunction returns true for spies created on object methods with spyOn()","@vitest/spy.isMockFunction returns true for getter and setter spies created with spyOn()","@vitest/spy.isMockFunction returns false for regular unmocked functions and async functions","@vitest/spy.isMockFunction returns false for non-function values such as null, undefined, objects, numbers, and strings","@vitest/spy.isMockFunction returns false for ordinary objects that mimic mock properties without being a function","@vitest/spy.isMockFunction returns false for original methods after spy.mockRestore() is invoked"],"goal":"verify @vitest/spy.isMockFunction in pkg:npm/%40vitest/spy@2.1.9","kind":"HOW","packages":["pkg:npm/%40vitest/spy@2.1.9"],"schemaVersion":1,"symbols":["@vitest/spy.isMockFunction"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40vitest/spy@2.1.9"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/spy@2.1.9","symbols":["@vitest/spy.isMockFunction"],"verifierAdapter":"node-typescript@1"}
import { fn, spyOn, isMockFunction } from '@vitest/spy';
export { fn, spyOn, isMockFunction };
export default isMockFunction;
{
"name": "sample-vitest-spy-is-mock-function",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-vitest-spy-is-mock-function",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@vitest/spy": "2.1.9"
}
},
"node_modules/@vitest/spy": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-2.1.9.tgz",
"integrity": "sha512-E1B35FwzXXTs9FHNK6bDszs7mtydNi5MIfUWpceJ8Xbfb1gBMscAnwLbEu+B44ed6W3XjL9/ehLPHR1fkf1KLQ==",
"license": "MIT",
"dependencies": {
"tinyspy": "^3.0.2"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"node_modules/tinyspy": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-3.0.2.tgz",
"integrity": "sha512-n1cw8k1k0x4pgA2+9XrOkFydTerNcJ1zWCO5Nn9scWHTD+5tp8dghT2x1uduQePZTZgd3Tupf+x9BxJjeJi77Q==",
"license": "MIT",
"engines": {
"node": ">=14.0.0"
}
}
}
}
{
"name": "sample-vitest-spy-is-mock-function",
"version": "1.0.0",
"type": "module",
"main": "index.mjs",
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@vitest/spy": "2.1.9"
}
}
{
"schemaVersion": 1,
"goal": "verify @vitest/spy.isMockFunction in pkg:npm/%40vitest/spy@2.1.9",
"kind": "HOW",
"packages": [
"pkg:npm/%40vitest/spy@2.1.9"
],
"symbols": [
"@vitest/spy.isMockFunction"
]
}
import assert from 'node:assert/strict';
import { fn, spyOn, isMockFunction } from '@vitest/spy';
// 1. isMockFunction returns true for mock functions created with fn()
{
const mockFn = fn();
assert.equal(isMockFunction(mockFn), true);
const mockWithImpl = fn((x) => x * 2);
assert.equal(isMockFunction(mockWithImpl), true);
assert.equal(mockWithImpl(5), 10);
}
// 2. isMockFunction returns true for spies created on object methods with spyOn()
{
const calculator = {
add(a, b) {
return a + b;
}
};
const spy = spyOn(calculator, 'add');
assert.equal(isMockFunction(spy), true);
assert.equal(isMockFunction(calculator.add), true);
assert.equal(calculator.add(2, 3), 5);
}
// 3. isMockFunction returns true for getter and setter spies created with spyOn()
{
const person = {
_age: 30,
get age() {
return this._age;
},
set age(val) {
this._age = val;
}
};
const getSpy = spyOn(person, 'age', 'get');
assert.equal(isMockFunction(getSpy), true);
assert.equal(person.age, 30);
const setSpy = spyOn(person, 'age', 'set');
assert.equal(isMockFunction(setSpy), true);
person.age = 35;
assert.equal(person._age, 35);
}
// 4. isMockFunction returns false for regular unmocked functions and async functions
{
function standardFunction() {}
const arrowFunction = () => {};
async function asyncFunction() {}
const generatorFunction = function* () {};
assert.equal(isMockFunction(standardFunction), false);
assert.equal(isMockFunction(arrowFunction), false);
assert.equal(isMockFunction(asyncFunction), false);
assert.equal(isMockFunction(generatorFunction), false);
}
// 5. isMockFunction returns false for non-function values such as null, undefined, objects, numbers, and strings
{
assert.equal(isMockFunction(null), false);
assert.equal(isMockFunction(undefined), false);
assert.equal(isMockFunction(0), false);
assert.equal(isMockFunction(123), false);
assert.equal(isMockFunction(''), false);
assert.equal(isMockFunction('mock'), false);
assert.equal(isMockFunction(true), false);
assert.equal(isMockFunction(Symbol('mock')), false);
assert.equal(isMockFunction({}), false);
assert.equal(isMockFunction([]), false);
}
// 6. isMockFunction returns false for ordinary objects that mimic mock properties without being a function
{
const fakeObj = { _isMockFunction: true };
assert.equal(isMockFunction(fakeObj), false);
const nonMockWithFalse = () => {};
nonMockWithFalse._isMockFunction = false;
assert.equal(isMockFunction(nonMockWithFalse), false);
}
// 7. isMockFunction returns false for original methods after spy.mockRestore() is invoked
{
const target = {
greet(name) {
return `Hello, ${name}!`;
}
};
const spy = spyOn(target, 'greet');
assert.equal(isMockFunction(target.greet), true);
spy.mockRestore();
assert.equal(isMockFunction(target.greet), false);
assert.equal(target.greet('world'), 'Hello, world!');
}
console.log('All @vitest/spy.isMockFunction contract assertions passed.');
Исходный сидер
аноним