{"record":{"id":"0788df423369605e","repo":"vitest-dev/vitest","slug":"schemamatching-expected-to-receive-a-standard-sche","errorCode":null,"errorMessage":"SchemaMatching expected to receive a Standard Schema.","messagePattern":"SchemaMatching expected to receive a Standard Schema\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/expect/src/jest-asymmetric-matchers.ts","lineNumber":404,"sourceCode":"  override getExpectedType() {\n    return 'number'\n  }\n\n  override toAsymmetricMatcher(): string {\n    return [\n      this.toString(),\n      this.sample,\n      `(${pluralize('digit', this.precision)})`,\n    ].join(' ')\n  }\n}\n\nexport class SchemaMatching extends AsymmetricMatcher<StandardSchemaV1<unknown, unknown>> {\n  private result: StandardSchemaV1.Result<unknown> | undefined\n\n  constructor(sample: StandardSchemaV1<unknown, unknown>, inverse = false) {\n    if (!isStandardSchema(sample)) {\n      throw new TypeError(\n        'SchemaMatching expected to receive a Standard Schema.',\n      )\n    }\n    super(sample, inverse)\n  }\n\n  asymmetricMatch(other: unknown): boolean {\n    const result = this.sample['~standard'].validate(other)\n\n    // Check if the result is a Promise (async validation)\n    if (result instanceof Promise) {\n      throw new TypeError('Async schema validation is not supported in asymmetric matchers.')\n    }\n\n    this.result = result\n    const pass = !this.result.issues || this.result.issues.length === 0\n\n    return this.inverse ? !pass : pass","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/expect/src/jest-asymmetric-matchers.ts#L386-L422","documentation":"SchemaMatching (expect.schemaMatching) requires a Standard Schema object — one exposing the '~standard' descriptor with a validate function. isStandardSchema(sample) returns false for plain objects, classes, or zod/valibot versions that predate Standard Schema support.","triggerScenarios":"expect.schemaMatching(sample) where sample lacks the '~standard' key (e.g. a raw z.object call on zod v3, a plain validation function, or a class instance).","commonSituations":"Using zod v3 (no Standard Schema) — Standard Schema landed in zod v4 / valibot v0.31+ / arktype; passing a Yup or Joi schema (no Standard Schema adapter); wrapping the schema in an extra layer.","solutions":["Use a schema library that implements Standard Schema (zod v4+, valibot, arktype) and pass the schema object directly.","Upgrade the schema library to a version that ships Standard Schema support.","If stuck on zod v3/Yup/Joi, write a custom matcher or upgrade rather than passing the raw schema."],"exampleFix":"// before (zod v3 — not a Standard Schema)\nimport { z } from 'zod' // v3\nexpect(payload).toEqual(expect.schemaMatching(z.object({ id: z.number() })))\n// after (zod v4 — Standard Schema compliant)\nimport { z } from 'zod' // v4\nexpect(payload).toEqual(expect.schemaMatching(z.object({ id: z.number() })))","handlingStrategy":"type-guard","validationCode":"function isStandardSchema(v): boolean {\n  return v != null && typeof v === 'object' && '~standard' in v && typeof v['~standard']?.validate === 'function'\n}\nfunction asSchemaMatching(schema) {\n  if (!isStandardSchema(schema)) {\n    throw new TypeError('Pass a Standard Schema (zod v4 / valibot / arktype)')\n  }\n  return expect.schemaMatching(schema)\n}","typeGuard":"function isStandardSchema(v): v is { '~standard': { validate: (v: unknown) => unknown } } {\n  return v != null && typeof v === 'object' && '~standard' in v && typeof (v as any)['~standard']?.validate === 'function'\n}","tryCatchPattern":null,"preventionTips":["Use a Standard Schema-compliant library (zod v4+, valibot, arktype).","Upgrade legacy zod v3/Yup/Joi setups rather than passing raw schemas.","Verify the '~standard' descriptor exists before passing the schema."],"tags":["expect","asymmetric-matcher","schema","validation"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}