{"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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/expect/src/jest-asymmetric-matchers.ts#L386-L422","documentation":"Thrown as a TypeError by the SchemaMatching asymmetric matcher constructor when the sample does not satisfy the Standard Schema spec (it must be an object/function with a '~standard' property whose validate is a function). expect.schemaMatching wraps any spec-compliant validator (zod, valibot, arktype, etc.).","triggerScenarios":"Constructing expect.schemaMatching(value) where value is a plain object, class instance, JSON schema, or anything lacking the '~standard' marker. The isStandardSchema() guard returns false.","commonSituations":"Passing a raw JSON Schema object (not a Standard Schema); passing a validator instance from a library version that doesn't expose '~standard'; passing a zod schema from a version before Standard Schema support was added.","solutions":["Pass a Standard Schema-compliant schema (zod v3.24+/v4, valibot >=1.0, arktype, etc.).","Upgrade the validation library to a version that exports the '~standard' interface.","For JSON Schema, wrap it with a Standard Schema adapter before passing."],"exampleFix":"// before\nimport rawSchema from './schema.json'\nexpect(value).toEqual(expect.schemaMatching(rawSchema))\n// after\nimport { z } from 'zod'\nconst schema = z.object({ id: z.number() })\nexpect(value).toEqual(expect.schemaMatching(schema))","handlingStrategy":"type-guard","validationCode":"import { isStandardSchema } from '@vitest/expect'\nif (!isStandardSchema(maybeSchema)) {\n  throw new TypeError('Pass a Standard Schema-compliant schema (zod/valibot/arktype)')\n}\nexpect(value).toEqual(expect.schemaMatching(maybeSchema))","typeGuard":"function isStandardSchemaLike(obj: unknown): obj is { '~standard': { validate: (v: unknown) => any } } {\n  return !!obj\n    && (typeof obj === 'object' || typeof obj === 'function')\n    && typeof (obj as any)?.['~standard']?.validate === 'function'\n}","tryCatchPattern":null,"preventionTips":["Use a Standard Schema-compliant validator library version (zod >=3.24, valibot >=1.0).","Don't pass raw JSON Schema; wrap it in a Standard Schema adapter.","Assert isStandardSchema() at the boundary where schemas enter your tests."],"tags":["expect","asymmetric-matcher","standard-schema","validation","typescript"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}