1
0

feat: ValueMatcher 支持 primitive 原始值简写,等价于 { equals: value }

This commit is contained in:
2026-05-19 17:07:47 +08:00
parent 8d8549d07f
commit 12cd05b04e
37 changed files with 1836 additions and 1022 deletions

View File

@@ -0,0 +1,22 @@
import type { ValueMatcherPrimitive } from "./types";
import { isValueMatcherObject } from "./matcher";
export function isValueMatcherPrimitive(value: unknown): value is ValueMatcherPrimitive {
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
}
export function normalizeExpectMatchers(expect: Record<string, unknown>, keys: string[]): void {
for (const key of keys) {
if (key in expect) {
expect[key] = normalizeValueMatcher(expect[key]);
}
}
}
export function normalizeValueMatcher(value: unknown): unknown {
if (value === undefined) return undefined;
if (isValueMatcherObject(value)) return value;
if (isValueMatcherPrimitive(value)) return { equals: value };
return value;
}