CodeSampleX

Ejemplo

@vitest/expect 2.1.9: Anything

Muestra verificada para npm @vitest/expect 2.1.9: Anything. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:63544fa43e4bd2e110625f5670728f8d86b9ce2a4d4e294ebf4c65f9b87a9726

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node linux 24 · ubuntu · glibc 2.39 x64 node npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify @vitest/expect.Anything in pkg:npm/%40vitest/expect@2.1.9
Paquetes
Símbolos
  • @vitest/expect.Anything
Entorno
node
Creado
2026-09-03T17:38:53Z

Contrato

  1. Anything instantiates an asymmetric matcher with Symbol.for('jest.asymmetricMatcher')
  2. asymmetricMatch returns true for non-null and non-undefined values including primitives, empty objects, and NaN
  3. asymmetricMatch returns false for null and undefined
  4. expect.anything returns an Anything instance compatible with asymmetric assertions
  5. toEqual passes when matching non-null values against Anything instances
  6. toEqual throws when matching null or undefined against Anything instances
  7. Anything matches nested object properties and array elements in deep structural assertions
  8. hasAsymmetric and isAsymmetric identify Anything instances as asymmetric matchers

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

NOTES.md
# @vitest/expect Anything Asymmetric Matcher Semantics

## Search Results
An initial search on `pkg:npm/%40vitest/expect@2.1.9` for symbol `@vitest/expect.Anything` returned `NO_SAFE_MATCH`. This clean-room sample verifies the contract and runtime behavior of the `Anything` asymmetric matcher class and `expect.anything()` factory helper.

## Key Behavior
- `Anything` is an asymmetric matcher extending `AsymmetricMatcher` with `$$typeof` matching `Symbol.for('jest.asymmetricMatcher')`.
- `Anything.asymmetricMatch(other)` returns `true` for any defined non-null value (including `0`, `""`, `false`, `NaN`, objects, and arrays), and returns `false` strictly for `null` and `undefined`.
- Both `new Anything()` and `expect.anything()` instantiate this matcher for use with standard assertions like `toEqual`.
- Inverted assertions correctly verify that `null` and `undefined` do not match `Anything`.
- `Anything` seamlessly integrates inside complex nested structures such as objects and arrays.
- Helper utilities `isAsymmetric` and `hasAsymmetric` correctly detect `Anything` instances.
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 @vitest/expect.Anything 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.Anything

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:65d1f4bb422a53649aac2d151325de71175dd31b47784d336488fd490ac2d0a9","contract":["Anything instantiates an asymmetric matcher with Symbol.for('jest.asymmetricMatcher')","asymmetricMatch returns true for non-null and non-undefined values including primitives, empty objects, and NaN","asymmetricMatch returns false for null and undefined","expect.anything returns an Anything instance compatible with asymmetric assertions","toEqual passes when matching non-null values against Anything instances","toEqual throws when matching null or undefined against Anything instances","Anything matches nested object properties and array elements in deep structural assertions","hasAsymmetric and isAsymmetric identify Anything instances as asymmetric matchers"],"goal":"verify @vitest/expect.Anything in pkg:npm/%40vitest/expect@2.1.9","kind":"HOW","packages":["pkg:npm/%40vitest/expect@2.1.9"],"schemaVersion":1,"symbols":["@vitest/expect.Anything"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","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.Anything"],"verifierAdapter":"node-typescript@1"}
index.mjs
import * as chai from 'chai';
import {
  JestChaiExpect,
  JestAsymmetricMatchers,
  JestExtend,
  Anything,
  isAsymmetric,
  hasAsymmetric
} from '@vitest/expect';

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

export const expect = chai.expect;

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

// 1. Anything instantiates an asymmetric matcher with Symbol.for('jest.asymmetricMatcher')
{
  const matcher = new Anything();
  assert.equal(matcher.$$typeof, Symbol.for('jest.asymmetricMatcher'));
  assert.equal(matcher.toString(), 'Anything');
  assert.equal(matcher.toAsymmetricMatcher(), 'Anything');
  assert.equal(isAsymmetric(matcher), true);
}

// 2. asymmetricMatch returns true for non-null and non-undefined values including primitives, empty objects, and NaN
{
  const matcher = new Anything();
  assert.equal(matcher.asymmetricMatch(0), true);
  assert.equal(matcher.asymmetricMatch(''), true);
  assert.equal(matcher.asymmetricMatch(false), true);
  assert.equal(Number.isNaN(NaN) && matcher.asymmetricMatch(NaN), true);
  assert.equal(matcher.asymmetricMatch({}), true);
  assert.equal(matcher.asymmetricMatch([]), true);
  assert.equal(matcher.asymmetricMatch(() => {}), true);
  assert.equal(matcher.asymmetricMatch(Symbol('test')), true);
}

// 3. asymmetricMatch returns false for null and undefined
{
  const matcher = new Anything();
  assert.equal(matcher.asymmetricMatch(null), false);
  assert.equal(matcher.asymmetricMatch(undefined), false);
}

// 4. expect.anything returns an Anything instance compatible with asymmetric assertions
{
  const matcher = expect.anything();
  assert.ok(matcher instanceof Anything);
  assert.equal(isAsymmetric(matcher), true);
}

// 5. toEqual passes when matching non-null values against Anything instances
{
  expect(42).toEqual(new Anything());
  expect('vitest').toEqual(new Anything());
  expect(true).toEqual(expect.anything());
  expect({ key: 'val' }).toEqual(expect.anything());
  expect([1, 2, 3]).toEqual(expect.anything());
}

// 6. toEqual throws when matching null or undefined against Anything instances
{
  assert.throws(() => {
    expect(null).toEqual(new Anything());
  }, /AssertionError|Anything/);

  assert.throws(() => {
    expect(undefined).toEqual(expect.anything());
  }, /AssertionError|Anything/);

  expect(null).not.toEqual(expect.anything());
  expect(undefined).not.toEqual(new Anything());
}

// 7. Anything matches nested object properties and array elements in deep structural assertions
{
  const payload = {
    id: 101,
    token: 'auth-token-xyz',
    metadata: { created: 123456, host: 'localhost' },
    items: ['alpha', 10],
  };

  expect(payload).toEqual({
    id: 101,
    token: expect.anything(),
    metadata: { created: expect.anything(), host: 'localhost' },
    items: [new Anything(), 10],
  });

  expect({ id: 101, token: null }).not.toEqual({
    id: 101,
    token: expect.anything(),
  });
}

// 8. hasAsymmetric and isAsymmetric identify Anything instances as asymmetric matchers
{
  assert.equal(hasAsymmetric({ field: new Anything() }), true);
  assert.equal(hasAsymmetric({ field: 'plain value' }), false);
  assert.equal(isAsymmetric(new Anything()), true);
  assert.equal(isAsymmetric('plain value'), false);
}

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

Seeder de origen

anónimo