vitest-dev/vitest · error · TypeError
SchemaMatching expected to receive a Standard Schema.
Error message
SchemaMatching expected to receive a Standard Schema.
What it means
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.).
Source
Thrown at packages/expect/src/jest-asymmetric-matchers.ts:404
override getExpectedType() {
return 'number'
}
override toAsymmetricMatcher(): string {
return [
this.toString(),
this.sample,
`(${pluralize('digit', this.precision)})`,
].join(' ')
}
}
export class SchemaMatching extends AsymmetricMatcher<StandardSchemaV1<unknown, unknown>> {
private result: StandardSchemaV1.Result<unknown> | undefined
constructor(sample: StandardSchemaV1<unknown, unknown>, inverse = false) {
if (!isStandardSchema(sample)) {
throw new TypeError(
'SchemaMatching expected to receive a Standard Schema.',
)
}
super(sample, inverse)
}
asymmetricMatch(other: unknown): boolean {
const result = this.sample['~standard'].validate(other)
// Check if the result is a Promise (async validation)
if (result instanceof Promise) {
throw new TypeError('Async schema validation is not supported in asymmetric matchers.')
}
this.result = result
const pass = !this.result.issues || this.result.issues.length === 0
return this.inverse ? !pass : passView on GitHub (pinned to d568f8ce37)
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.
Example fix
// before
import rawSchema from './schema.json'
expect(value).toEqual(expect.schemaMatching(rawSchema))
// after
import { z } from 'zod'
const schema = z.object({ id: z.number() })
expect(value).toEqual(expect.schemaMatching(schema)) Defensive patterns
Strategy: type-guard
Validate before calling
import { isStandardSchema } from '@vitest/expect'
if (!isStandardSchema(maybeSchema)) {
throw new TypeError('Pass a Standard Schema-compliant schema (zod/valibot/arktype)')
}
expect(value).toEqual(expect.schemaMatching(maybeSchema)) Type guard
function isStandardSchemaLike(obj: unknown): obj is { '~standard': { validate: (v: unknown) => any } } {
return !!obj
&& (typeof obj === 'object' || typeof obj === 'function')
&& typeof (obj as any)?.['~standard']?.validate === 'function'
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Async schema validation is not supported in asymmetric match
- Expected is not a string
- You must provide an object to ${this.toString()}, not '${typ
- You must provide an array to ${this.toString()}, not '${type
- any() expects to be passed a constructor function. Please pa
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/0788df423369605e.json.
Report an issue: GitHub.