Exemple
@vitest/expect 2.1.9: JestAsymmetricMatchers
Échantillon vérifié pour npm @vitest/expect 2.1.9: JestAsymmetricMatchers. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.
sha256:9192b0d35b8453be9df45fd1a7068ac86bea08f247cd050bbd97fe54b4cecf59
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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-03 |
Cas
HOW- Objectif
- verify @vitest/expect.JestAsymmetricMatchers in pkg:npm/%40vitest/expect@2.1.9
- Paquets
- Symboles
-
- @vitest/expect.JestAsymmetricMatchers
- Environnement
- node 22.23.2
- Créé
- 2026-09-03T18:44:29Z
Contrat
- assert JestAsymmetricMatchers is a function Chai plugin that registers matcher methods onto chai.expect
- assert expect.anything matches defined values and rejects null and undefined
- assert expect.any matches values by constructor type and rejects non-matching types
- assert expect.stringContaining and expect.not.stringContaining match substrings and inverted substrings
- assert expect.objectContaining and expect.not.objectContaining match partial object properties and inverted subsets
- assert expect.arrayContaining and expect.not.arrayContaining match array element subsets and inverted subsets
- assert expect.stringMatching and expect.not.stringMatching match regular expressions and inverted patterns
- assert expect.closeTo and expect.not.closeTo match floating point values within precision tolerances
- assert JestAsymmetricMatchers integrates with equals for deep structural comparison across objects and arrays
Fichiers
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Code source
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/expect.JestAsymmetricMatchers in pkg:npm/%40vitest/expect@2.1.9
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40vitest/expect@2.1.9
Demonstrate these symbols/APIs:
- @vitest/expect.JestAsymmetricMatchers
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:2be1cb21c29bc39ca69c5c4511a01a25d20853ebcf9d87ce3c0d1a5c5d541549","contract":["assert JestAsymmetricMatchers is a function Chai plugin that registers matcher methods onto chai.expect","assert expect.anything matches defined values and rejects null and undefined","assert expect.any matches values by constructor type and rejects non-matching types","assert expect.stringContaining and expect.not.stringContaining match substrings and inverted substrings","assert expect.objectContaining and expect.not.objectContaining match partial object properties and inverted subsets","assert expect.arrayContaining and expect.not.arrayContaining match array element subsets and inverted subsets","assert expect.stringMatching and expect.not.stringMatching match regular expressions and inverted patterns","assert expect.closeTo and expect.not.closeTo match floating point values within precision tolerances","assert JestAsymmetricMatchers integrates with equals for deep structural comparison across objects and arrays"],"goal":"verify @vitest/expect.JestAsymmetricMatchers in pkg:npm/%40vitest/expect@2.1.9","kind":"HOW","packages":["pkg:npm/%40vitest/expect@2.1.9"],"schemaVersion":1,"symbols":["@vitest/expect.JestAsymmetricMatchers"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40vitest/expect@2.1.9"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/expect@2.1.9","symbols":["@vitest/expect.JestAsymmetricMatchers"],"verifierAdapter":"node-typescript@1"}
import * as chai from 'chai';
import {
JestAsymmetricMatchers,
equals,
} from '@vitest/expect';
// Register the JestAsymmetricMatchers plugin on chai
chai.use(JestAsymmetricMatchers);
export const expect = chai.expect;
/**
* Registers the JestAsymmetricMatchers plugin on a given Chai instance.
*
* @param {object} chaiInstance - The Chai instance to register the plugin with.
* @returns {object} The Chai instance with asymmetric matchers attached.
*/
export function registerAsymmetricMatchers(chaiInstance) {
chaiInstance.use(JestAsymmetricMatchers);
return chaiInstance;
}
/**
* Validates an actual value against an expected pattern containing asymmetric matchers.
*
* @param {unknown} actual - The actual value or data structure.
* @param {unknown} expected - The expected value or pattern.
* @returns {boolean} True if actual matches the pattern.
*/
export function matchPattern(actual, expected) {
return equals(actual, expected);
}
export {
JestAsymmetricMatchers,
equals,
};
{
"name": "sample-vitest-expect-jest-asymmetric-matchers",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-vitest-expect-jest-asymmetric-matchers",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@vitest/expect": "2.1.9"
}
},
"node_modules/@vitest/expect": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.9.tgz",
"integrity": "sha512-UJCIkTBenHeKT1TTlKMJWy1laZewsRIzYighyYiJKZreqtdxSos/S1t+ktRMQWu2CKqaarrkeszJx1cgC5tGZw==",
"license": "MIT",
"dependencies": {
"@vitest/spy": "2.1.9",
"@vitest/utils": "2.1.9",
"chai": "^5.1.2",
"tinyrainbow": "^1.2.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"node_modules/@vitest/pretty-format": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-2.1.9.tgz",
"integrity": "sha512-KhRIdGV2U9HOUzxfiHmY8IFHTdqtOhIzCpd8WRdJiE7D/HUcZVD0EgQCVjm+Q9gkUXWgBvMmTtZgIG48wq7sOQ==",
"license": "MIT",
"dependencies": {
"tinyrainbow": "^1.2.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"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/@vitest/utils": {
"version": "2.1.9",
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-2.1.9.tgz",
"integrity": "sha512-v0psaMSkNJ3A2NMrUEHFRzJtDPFn+/VWZ5WxImB21T9fjucJRmS7xCS3ppEnARb9y11OAzaD+P2Ps+b+BGX5iQ==",
"license": "MIT",
"dependencies": {
"@vitest/pretty-format": "2.1.9",
"loupe": "^3.1.2",
"tinyrainbow": "^1.2.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
}
},
"node_modules/assertion-error": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",
"integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",
"license": "MIT",
"engines": {
"node": ">=12"
}
},
"node_modules/chai": {
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/chai/-/chai-5.3.3.tgz",
"integrity": "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw==",
"license": "MIT",
"dependencies": {
"assertion-error": "^2.0.1",
"check-error": "^2.1.1",
"deep-eql": "^5.0.1",
"loupe": "^3.1.0",
"pathval": "^2.0.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/check-error": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.3.tgz",
"integrity": "sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA==",
"license": "MIT",
"engines": {
"node": ">= 16"
}
},
"node_modules/deep-eql": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
"integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/loupe": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz",
"integrity": "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==",
"license": "MIT"
},
"node_modules/pathval": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.1.tgz",
"integrity": "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ==",
"license": "MIT",
"engines": {
"node": ">= 14.16"
}
},
"node_modules/tinyrainbow": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-1.2.0.tgz",
"integrity": "sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==",
"license": "MIT",
"engines": {
"node": ">=14.0.0"
}
},
"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-expect-jest-asymmetric-matchers",
"version": "1.0.0",
"description": "Clean-room verification sample for @vitest/expect JestAsymmetricMatchers",
"type": "module",
"main": "index.mjs",
"scripts": {
"test": "node test/contract.mjs"
},
"license": "MIT-0",
"dependencies": {
"@vitest/expect": "2.1.9"
}
}
{
"schemaVersion": 1,
"goal": "verify @vitest/expect.JestAsymmetricMatchers in pkg:npm/%40vitest/expect@2.1.9",
"kind": "HOW",
"packages": [
"pkg:npm/%40vitest/expect@2.1.9"
],
"symbols": [
"@vitest/expect.JestAsymmetricMatchers"
]
}
import assert from 'node:assert/strict';
import {
expect,
JestAsymmetricMatchers,
registerAsymmetricMatchers,
matchPattern,
equals,
} from '../index.mjs';
async function runContract() {
// 1. assert JestAsymmetricMatchers is a function Chai plugin that registers matcher methods onto chai.expect
assert.strictEqual(typeof JestAsymmetricMatchers, 'function');
assert.strictEqual(typeof expect.anything, 'function');
assert.strictEqual(typeof expect.any, 'function');
assert.strictEqual(typeof expect.stringContaining, 'function');
assert.strictEqual(typeof expect.objectContaining, 'function');
assert.strictEqual(typeof expect.arrayContaining, 'function');
assert.strictEqual(typeof expect.stringMatching, 'function');
assert.strictEqual(typeof expect.closeTo, 'function');
assert.strictEqual(typeof expect.not, 'object');
assert.strictEqual(typeof expect.not.stringContaining, 'function');
assert.strictEqual(typeof expect.not.objectContaining, 'function');
assert.strictEqual(typeof expect.not.arrayContaining, 'function');
assert.strictEqual(typeof expect.not.stringMatching, 'function');
assert.strictEqual(typeof expect.not.closeTo, 'function');
// Verify custom chai registration helper
const customChai = { expect: {} };
const customUtils = {
addMethod(ctx, name, fn) {
ctx[name] = fn;
},
};
JestAsymmetricMatchers(customChai, customUtils);
assert.strictEqual(typeof customChai.expect.anything, 'function');
assert.strictEqual(typeof customChai.expect.not.stringContaining, 'function');
// 2. assert expect.anything matches defined values and rejects null and undefined
const anythingMatcher = expect.anything();
assert.strictEqual(anythingMatcher.asymmetricMatch(0), true);
assert.strictEqual(anythingMatcher.asymmetricMatch(''), true);
assert.strictEqual(anythingMatcher.asymmetricMatch(false), true);
assert.strictEqual(anythingMatcher.asymmetricMatch({}), true);
assert.strictEqual(anythingMatcher.asymmetricMatch([]), true);
assert.strictEqual(anythingMatcher.asymmetricMatch(null), false);
assert.strictEqual(anythingMatcher.asymmetricMatch(undefined), false);
// 3. assert expect.any matches values by constructor type and rejects non-matching types
const stringMatcher = expect.any(String);
const numberMatcher = expect.any(Number);
const fnMatcher = expect.any(Function);
assert.strictEqual(stringMatcher.asymmetricMatch('test-string'), true);
assert.strictEqual(stringMatcher.asymmetricMatch(123), false);
assert.strictEqual(numberMatcher.asymmetricMatch(42), true);
assert.strictEqual(numberMatcher.asymmetricMatch('42'), false);
assert.strictEqual(fnMatcher.asymmetricMatch(() => {}), true);
assert.strictEqual(fnMatcher.asymmetricMatch({}), false);
// 4. assert expect.stringContaining and expect.not.stringContaining match substrings and inverted substrings
const hasSub = expect.stringContaining('bar');
const notHasSub = expect.not.stringContaining('baz');
assert.strictEqual(hasSub.asymmetricMatch('foobarbaz'), true);
assert.strictEqual(hasSub.asymmetricMatch('foofoo'), false);
assert.strictEqual(notHasSub.asymmetricMatch('foobar'), true);
assert.strictEqual(notHasSub.asymmetricMatch('foobarbaz'), false);
// 5. assert expect.objectContaining and expect.not.objectContaining match partial object properties and inverted subsets
const objSub = expect.objectContaining({ role: 'admin' });
const notObjSub = expect.not.objectContaining({ role: 'guest' });
assert.strictEqual(objSub.asymmetricMatch({ role: 'admin', active: true }), true);
assert.strictEqual(objSub.asymmetricMatch({ role: 'user', active: true }), false);
assert.strictEqual(notObjSub.asymmetricMatch({ role: 'admin' }), true);
assert.strictEqual(notObjSub.asymmetricMatch({ role: 'guest', id: 1 }), false);
// 6. assert expect.arrayContaining and expect.not.arrayContaining match array element subsets and inverted subsets
const arrSub = expect.arrayContaining([10, 20]);
const notArrSub = expect.not.arrayContaining([99]);
assert.strictEqual(arrSub.asymmetricMatch([5, 10, 15, 20]), true);
assert.strictEqual(arrSub.asymmetricMatch([5, 10]), false);
assert.strictEqual(notArrSub.asymmetricMatch([1, 2, 3]), true);
assert.strictEqual(notArrSub.asymmetricMatch([1, 99, 3]), false);
// 7. assert expect.stringMatching and expect.not.stringMatching match regular expressions and inverted patterns
const reMatch = expect.stringMatching(/^csx-[a-z]+-\d+$/);
const notReMatch = expect.not.stringMatching(/\d{4}/);
assert.strictEqual(reMatch.asymmetricMatch('csx-farm-1'), true);
assert.strictEqual(reMatch.asymmetricMatch('other-farm-1'), false);
assert.strictEqual(notReMatch.asymmetricMatch('csx-123'), true);
assert.strictEqual(notReMatch.asymmetricMatch('csx-1234'), false);
// 8. assert expect.closeTo and expect.not.closeTo match floating point values within precision tolerances
const close = expect.closeTo(0.3, 2);
const notClose = expect.not.closeTo(1.0, 1);
assert.strictEqual(close.asymmetricMatch(0.1 + 0.2), true);
assert.strictEqual(close.asymmetricMatch(0.35), false);
assert.strictEqual(notClose.asymmetricMatch(2.5), true);
assert.strictEqual(notClose.asymmetricMatch(1.01), false);
// 9. assert JestAsymmetricMatchers integrates with equals for deep structural comparison across objects and arrays
const complexData = {
id: 101,
name: 'Sample User',
tags: ['active', 'verified', 'admin'],
score: 98.765,
details: {
bio: 'CodeSampleX verified author',
created: new Date('2026-09-03'),
},
};
const pattern = {
id: expect.any(Number),
name: expect.stringContaining('User'),
tags: expect.arrayContaining(['verified']),
score: expect.closeTo(98.76, 1),
details: expect.objectContaining({
bio: expect.stringMatching(/verified author/),
created: expect.anything(),
}),
};
assert.strictEqual(matchPattern(complexData, pattern), true);
assert.strictEqual(equals(complexData, pattern), true);
const mismatchedData = {
...complexData,
tags: ['active'],
};
assert.strictEqual(matchPattern(mismatchedData, pattern), false);
console.log('Contract assertions passed successfully.');
}
runContract().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
Seeder d'origine
anonyme