示例
@vitest/expect 2.1.9: JestChaiExpect
已验证示例 — npm @vitest/expect 2.1.9: JestChaiExpect. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: assert JestChaiExpect is a function Chai plugin that…
sha256:c9478010b609ee0fe0e41f5a723f37f068470bfddd757b316130f0c4b17b1959
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify @vitest/expect.JestChaiExpect in pkg:npm/%40vitest/expect@2.1.9
- 符号
-
- @vitest/expect.JestChaiExpect
- 环境
- node 22.23.2
- 创建时间
- 2026-09-03T21:53:39Z
契约
- assert JestChaiExpect is a function Chai plugin that registers Jest matchers onto chai.Assertion.prototype and chai.expect
- assert toBe validates primitive and referential equality using Object.is and rejects mismatched values
- assert toEqual performs deep equality comparison across objects arrays and nested structures
- assert toStrictEqual performs strict equality checking types prototype and undefined properties
- assert toBeTruthy and toBeFalsy evaluate boolean truthiness of values
- assert toBeNull toBeUndefined toBeDefined and toBeNaN evaluate precise primitive states
- assert toBeGreaterThan toBeGreaterThanOrEqual toBeLessThan and toBeLessThanOrEqual compare numeric values
- assert toMatch validates string substrings and regular expressions
- assert toMatchObject validates partial object properties against target objects
- assert toContain validates element inclusion in arrays and substring inclusion in strings
- assert toContainEqual validates element presence in arrays using deep equality
- assert toHaveLength validates the length property of collections and strings
- assert toHaveProperty validates property existence and value at specified object key paths
- assert toThrow validates function error throwing with message patterns and error constructors
- assert negation modifier not inverts matchers correctly across assertions
文件
- 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/expect.JestChaiExpect 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.JestChaiExpect
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:ee4e23674dc86ab74e26c48e6e100813b9a1c858b377d32246f114afb6c50c0d","contract":["assert JestChaiExpect is a function Chai plugin that registers Jest matchers onto chai.Assertion.prototype and chai.expect","assert toBe validates primitive and referential equality using Object.is and rejects mismatched values","assert toEqual performs deep equality comparison across objects arrays and nested structures","assert toStrictEqual performs strict equality checking types prototype and undefined properties","assert toBeTruthy and toBeFalsy evaluate boolean truthiness of values","assert toBeNull toBeUndefined toBeDefined and toBeNaN evaluate precise primitive states","assert toBeGreaterThan toBeGreaterThanOrEqual toBeLessThan and toBeLessThanOrEqual compare numeric values","assert toMatch validates string substrings and regular expressions","assert toMatchObject validates partial object properties against target objects","assert toContain validates element inclusion in arrays and substring inclusion in strings","assert toContainEqual validates element presence in arrays using deep equality","assert toHaveLength validates the length property of collections and strings","assert toHaveProperty validates property existence and value at specified object key paths","assert toThrow validates function error throwing with message patterns and error constructors","assert negation modifier not inverts matchers correctly across assertions"],"goal":"verify @vitest/expect.JestChaiExpect in pkg:npm/%40vitest/expect@2.1.9","kind":"HOW","packages":["pkg:npm/%40vitest/expect@2.1.9"],"schemaVersion":1,"symbols":["@vitest/expect.JestChaiExpect"]},"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.JestChaiExpect"],"verifierAdapter":"node-typescript@1"}
import * as chai from 'chai';
import {
JestChaiExpect,
} from '@vitest/expect';
// Register the JestChaiExpect plugin on chai
chai.use(JestChaiExpect);
export const expect = chai.expect;
/**
* Registers the JestChaiExpect plugin on a given Chai instance.
*
* @param {object} chaiInstance - The Chai instance to register the plugin with.
* @returns {object} The Chai instance with Jest matchers attached.
*/
export function registerJestChaiExpect(chaiInstance) {
chaiInstance.use(JestChaiExpect);
return chaiInstance;
}
export {
JestChaiExpect,
};
{
"name": "sample-vitest-expect-jest-chai-expect",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-vitest-expect-jest-chai-expect",
"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-chai-expect",
"version": "1.0.0",
"description": "Clean-room verification sample for @vitest/expect JestChaiExpect",
"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.JestChaiExpect in pkg:npm/%40vitest/expect@2.1.9",
"kind": "HOW",
"packages": [
"pkg:npm/%40vitest/expect@2.1.9"
],
"symbols": [
"@vitest/expect.JestChaiExpect"
]
}
import assert from 'node:assert/strict';
import * as chai from 'chai';
import {
expect,
JestChaiExpect,
registerJestChaiExpect,
} from '../index.mjs';
async function runContract() {
// 1. assert JestChaiExpect is a function Chai plugin that registers Jest matchers onto chai.Assertion.prototype and chai.expect
assert.strictEqual(typeof JestChaiExpect, 'function');
assert.strictEqual(typeof expect, 'function');
// Verify Chai registration helper
const registered = registerJestChaiExpect(chai);
assert.strictEqual(registered, chai);
assert.strictEqual(typeof chai.Assertion.prototype.toBe, 'function');
assert.strictEqual(typeof chai.Assertion.prototype.toEqual, 'function');
assert.strictEqual(typeof chai.Assertion.prototype.toStrictEqual, 'function');
assert.strictEqual(typeof chai.Assertion.prototype.toBeTruthy, 'function');
assert.strictEqual(typeof chai.Assertion.prototype.toBeFalsy, 'function');
assert.strictEqual(typeof chai.Assertion.prototype.toMatchObject, 'function');
// 2. assert toBe validates primitive and referential equality using Object.is and rejects mismatched values
expect(42).toBe(42);
expect('alpha').toBe('alpha');
expect(true).toBe(true);
const objRef = { id: 1 };
expect(objRef).toBe(objRef);
assert.throws(() => expect(42).toBe(43), /AssertionError/);
assert.throws(() => expect({ id: 1 }).toBe({ id: 1 }), /AssertionError/);
// 3. assert toEqual performs deep equality comparison across objects arrays and nested structures
expect({ x: 1, y: [10, 20] }).toEqual({ x: 1, y: [10, 20] });
expect(['a', 'b', { c: 3 }]).toEqual(['a', 'b', { c: 3 }]);
assert.throws(() => expect({ x: 1 }).toEqual({ x: 2 }), /AssertionError/);
// 4. assert toStrictEqual performs strict equality checking types prototype and undefined properties
class ModelA {
constructor(val) {
this.val = val;
}
}
class ModelB {
constructor(val) {
this.val = val;
}
}
expect(new ModelA('test')).toStrictEqual(new ModelA('test'));
assert.throws(() => expect(new ModelA('test')).toStrictEqual(new ModelB('test')), /AssertionError/);
assert.throws(() => expect({ a: undefined, b: 1 }).toStrictEqual({ b: 1 }), /AssertionError/);
// 5. assert toBeTruthy and toBeFalsy evaluate boolean truthiness of values
expect('truthy string').toBeTruthy();
expect(100).toBeTruthy();
expect({}).toBeTruthy();
expect(0).toBeFalsy();
expect('').toBeFalsy();
expect(null).toBeFalsy();
expect(undefined).toBeFalsy();
assert.throws(() => expect(false).toBeTruthy(), /AssertionError/);
assert.throws(() => expect(true).toBeFalsy(), /AssertionError/);
// 6. assert toBeNull toBeUndefined toBeDefined and toBeNaN evaluate precise primitive states
expect(null).toBeNull();
expect(undefined).toBeUndefined();
expect('defined value').toBeDefined();
expect(Number.NaN).toBeNaN();
assert.throws(() => expect(undefined).toBeNull(), /AssertionError/);
assert.throws(() => expect(null).toBeUndefined(), /AssertionError/);
assert.throws(() => expect(undefined).toBeDefined(), /AssertionError/);
assert.throws(() => expect(123).toBeNaN(), /AssertionError/);
// 7. assert toBeGreaterThan toBeGreaterThanOrEqual toBeLessThan and toBeLessThanOrEqual compare numeric values
expect(20).toBeGreaterThan(10);
expect(20).toBeGreaterThanOrEqual(20);
expect(10).toBeLessThan(20);
expect(10).toBeLessThanOrEqual(10);
assert.throws(() => expect(5).toBeGreaterThan(10), /AssertionError/);
assert.throws(() => expect(15).toBeLessThan(10), /AssertionError/);
// 8. assert toMatch validates string substrings and regular expressions
expect('code-sample-x').toMatch('sample');
expect('sample-12345').toMatch(/^sample-\d{5}$/);
assert.throws(() => expect('sample-abc').toMatch(/\d+/), /AssertionError/);
// 9. assert toMatchObject validates partial object properties against target objects
const payload = {
id: 'req_123',
status: 'active',
metadata: { env: 'production', region: 'us-west' },
};
expect(payload).toMatchObject({
status: 'active',
metadata: { env: 'production' },
});
assert.throws(() => expect(payload).toMatchObject({ status: 'pending' }), /AssertionError/);
// 10. assert toContain validates element inclusion in arrays and substring inclusion in strings
expect([1, 2, 3, 4]).toContain(3);
expect('vitest testing framework').toContain('testing');
assert.throws(() => expect([1, 2]).toContain(5), /AssertionError/);
assert.throws(() => expect('vitest').toContain('jest'), /AssertionError/);
// 11. assert toContainEqual validates element presence in arrays using deep equality
const itemList = [{ id: 1, name: 'first' }, { id: 2, name: 'second' }];
expect(itemList).toContainEqual({ id: 1, name: 'first' });
assert.throws(() => expect(itemList).toContainEqual({ id: 3, name: 'third' }), /AssertionError/);
// 12. assert toHaveLength validates the length property of collections and strings
expect(['a', 'b', 'c']).toHaveLength(3);
expect('length-check').toHaveLength(12);
assert.throws(() => expect([1, 2]).toHaveLength(5), /AssertionError/);
// 13. assert toHaveProperty validates property existence and value at specified object key paths
const config = {
server: {
host: 'localhost',
port: 8080,
},
};
expect(config).toHaveProperty('server.host', 'localhost');
expect(config).toHaveProperty('server.port');
assert.throws(() => expect(config).toHaveProperty('server.ssl'), /AssertionError/);
// 14. assert toThrow validates function error throwing with message patterns and error constructors
const throwError = () => {
throw new RangeError('Index out of range');
};
expect(throwError).toThrow('out of range');
expect(throwError).toThrow(RangeError);
expect(throwError).toThrow(/Index/);
assert.throws(() => expect(() => {}).toThrow(), /AssertionError/);
// 15. assert negation modifier not inverts matchers correctly across assertions
expect(10).not.toBe(20);
expect({ a: 1 }).not.toEqual({ a: 2 });
expect('hello').not.toContain('world');
expect(() => {}).not.toThrow();
assert.throws(() => expect(10).not.toBe(10), /AssertionError/);
console.log('Contract assertions passed successfully.');
}
runContract().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
原始种子者
匿名