CodeSampleX

サンプル

@vitest/expect 2.1.9: expect

検証済みサンプル — npm @vitest/expect 2.1.9: expect. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: expect performs strict primitive equality and .not…

sha256:d78d8125c86fe398fbe87d07a9b499b550d75472e89f716489bf9cfe08bce9f4

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

ケース

HOW
ゴール
verify expect in pkg:npm/%40vitest/expect@2.1.9
パッケージ
シンボル
  • expect
環境
node 22.23.2
作成日
2026-08-27T09:30:55Z

コントラクト

  1. expect performs strict primitive equality and .not inversion
  2. toEqual and toStrictEqual perform deep object and array structural equality assertions
  3. toMatchObject and toHaveProperty verify subset structures and nested object properties
  4. toContain and toContainEqual assert element presence and membership in arrays and strings
  5. toBeGreaterThan, toBeLessThan, and toBeCloseTo validate numeric relationships and floating point values
  6. toBeTypeOf and toSatisfy evaluate type classifications and custom predicate functions
  7. toThrow verifies exception throwing and error type matching
  8. Asymmetric matchers stringContaining, stringMatching, objectContaining, arrayContaining, any, and anything match partial values
  9. expect.extend registers custom matchers with custom pass and failure message logic
  10. getState and setState inspect and update matcher execution context

ファイル

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
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 expect 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:
  - expect

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.
csx.json
{"case":{"caseId":"case:sha256:90e607ce4e1b84935e1dc9b36c7ce8db05969b9a5c94b09e7f0f04d8d3954633","contract":["expect performs strict primitive equality and .not inversion","toEqual and toStrictEqual perform deep object and array structural equality assertions","toMatchObject and toHaveProperty verify subset structures and nested object properties","toContain and toContainEqual assert element presence and membership in arrays and strings","toBeGreaterThan, toBeLessThan, and toBeCloseTo validate numeric relationships and floating point values","toBeTypeOf and toSatisfy evaluate type classifications and custom predicate functions","toThrow verifies exception throwing and error type matching","Asymmetric matchers stringContaining, stringMatching, objectContaining, arrayContaining, any, and anything match partial values","expect.extend registers custom matchers with custom pass and failure message logic","getState and setState inspect and update matcher execution context"],"goal":"verify expect in pkg:npm/%40vitest/expect@2.1.9","kind":"HOW","packages":["pkg:npm/%40vitest/expect@2.1.9"],"schemaVersion":1,"symbols":["expect"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","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":["expect"],"verifierAdapter":"node-typescript@1"}
index.mjs
import * as chai from 'chai';
import {
  JestChaiExpect,
  JestAsymmetricMatchers,
  JestExtend,
  getState,
  setState,
  equals,
  isA,
  isAsymmetric,
  hasAsymmetric,
  StringContaining,
  StringMatching,
  ObjectContaining,
  ArrayContaining,
  Any,
  Anything
} from '@vitest/expect';

chai.use(JestChaiExpect);
chai.use(JestAsymmetricMatchers);
chai.use(JestExtend);

export const expect = chai.expect;

export {
  JestChaiExpect,
  JestAsymmetricMatchers,
  JestExtend,
  getState,
  setState,
  equals,
  isA,
  isAsymmetric,
  hasAsymmetric,
  StringContaining,
  StringMatching,
  ObjectContaining,
  ArrayContaining,
  Any,
  Anything
};
package-lock.json
{
  "name": "sample-vitest-expect",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vitest-expect",
      "version": "1.0.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"
      }
    }
  }
}
package.json
{
  "name": "sample-vitest-expect",
  "version": "1.0.0",
  "description": "Clean-room verification sample for expect in @vitest/expect",
  "type": "module",
  "main": "index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@vitest/expect": "2.1.9"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify expect in pkg:npm/%40vitest/expect@2.1.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/expect@2.1.9"
  ],
  "symbols": [
    "expect"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  expect,
  getState,
  setState,
  equals,
  isA,
  isAsymmetric,
  hasAsymmetric,
  StringContaining,
  StringMatching,
  ObjectContaining,
  ArrayContaining,
  Any,
  Anything
} from '../index.mjs';

// 1. Basic expect assertion function and .not negation
{
  assert.equal(typeof expect, 'function');
  expect(42).toBe(42);
  expect('vitest').toBe('vitest');
  expect(true).toBe(true);
  expect(false).toBe(false);
  expect(null).toBeNull();
  expect(undefined).toBeUndefined();
  expect(NaN).toBeNaN();
  expect(10).not.toBe(20);
  expect('hello').not.toBe('world');
}

// 2. toEqual and toStrictEqual deep equality assertions
{
  const obj1 = { id: 1, tags: ['a', 'b'], meta: { count: 3 } };
  const obj2 = { id: 1, tags: ['a', 'b'], meta: { count: 3 } };
  expect(obj1).toEqual(obj2);
  expect(obj1).toStrictEqual(obj2);
  expect([1, 2, 3]).toEqual([1, 2, 3]);
  expect([1, 2]).not.toEqual([1, 3]);
}

// 3. toMatchObject and toHaveProperty structural inspection
{
  const user = { id: 100, name: 'Alex', profile: { role: 'admin', level: 5 } };
  expect(user).toMatchObject({ name: 'Alex', profile: { role: 'admin' } });
  expect(user).toHaveProperty('profile.role', 'admin');
  expect(user).toHaveProperty('id', 100);
}

// 4. toContain and toContainEqual containment assertions
{
  expect(['apple', 'banana', 'orange']).toContain('banana');
  expect('javascript string matcher').toContain('string');
  expect([{ key: 'a' }, { key: 'b' }]).toContainEqual({ key: 'b' });
  expect([10, 20, 30]).toHaveLength(3);
  expect('hello').toHaveLength(5);
}

// 5. Numerical range assertions (toBeGreaterThan, toBeLessThan, toBeCloseTo)
{
  expect(15).toBeGreaterThan(10);
  expect(15).toBeGreaterThanOrEqual(15);
  expect(5).toBeLessThan(10);
  expect(5).toBeLessThanOrEqual(5);
  expect(0.1 + 0.2).toBeCloseTo(0.3, 5);
}

// 6. Type and predicate assertions (toBeTypeOf, toSatisfy)
{
  expect('test-string').toBeTypeOf('string');
  expect(12345).toBeTypeOf('number');
  expect(true).toBeTypeOf('boolean');
  expect(Symbol('vitest')).toBeTypeOf('symbol');
  expect(20).toSatisfy(n => n % 5 === 0);
  expect('admin@example.com').toSatisfy(s => s.includes('@'));
}

// 7. Exception assertions (toThrow, toThrowError)
{
  expect(() => {
    throw new Error('invalid operation');
  }).toThrow('invalid operation');

  expect(() => {
    throw new TypeError('invalid argument');
  }).toThrow(TypeError);

  expect(() => {
    // no error thrown
  }).not.toThrow();
}

// 8. Asymmetric matchers attached to expect and constructor classes
{
  expect('sample-test-case').toEqual(expect.stringContaining('test'));
  expect('vitest-2.1.9').toEqual(expect.stringMatching(/^vitest-\d+\.\d+\.\d+$/));
  expect({ x: 1, y: 2, extra: true }).toEqual(expect.objectContaining({ x: 1, y: 2 }));
  expect([1, 2, 3, 4]).toEqual(expect.arrayContaining([2, 4]));
  expect('hello').toEqual(expect.any(String));
  expect(99).toEqual(expect.any(Number));
  expect({ custom: true }).toEqual(expect.anything());

  // Using exported matcher constructors
  expect('prefix-val-suffix').toEqual(new StringContaining('val'));
  expect('abc-123').toEqual(new StringMatching(/^abc-\d+$/));
  expect({ a: 10, b: 20 }).toEqual(new ObjectContaining({ a: 10 }));
  expect([10, 20, 30]).toEqual(new ArrayContaining([20]));
  expect('str').toEqual(new Any(String));
  expect({}).toEqual(new Anything());
}

// 9. expect.extend registers custom matchers
{
  expect.extend(expect, {
    toBeWithinRange(received, floor, ceiling) {
      const pass = received >= floor && received <= ceiling;
      return {
        pass,
        message: () => `expected ${received} ${pass ? 'not ' : ''}to be within range [${floor}, ${ceiling}]`,
      };
    },
  });

  expect(50).toBeWithinRange(1, 100);
  expect(150).not.toBeWithinRange(1, 100);
}

// 10. getState and setState lifecycle management
{
  setState({ currentTestName: 'expect-suite-verification', assertionCount: 10 }, expect);
  const state = getState(expect);
  assert.equal(state.currentTestName, 'expect-suite-verification');
  assert.equal(state.assertionCount, 10);

  assert.equal(equals({ k: 1 }, { k: 1 }), true);
  assert.equal(equals({ k: 1 }, { k: 2 }), false);
  assert.equal(isA('String', 'hello'), true);
  assert.equal(isA('Number', 42), true);
  assert.equal(isAsymmetric(new Any(String)), true);
  assert.equal(hasAsymmetric({ matcher: new Any(Number) }), true);
}

console.log('All @vitest/expect contract assertions passed successfully.');

オリジンシーダー

匿名