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,31 @@
import { describe, expect, test } from "bun:test";
import { normalizeExpectMatchers, normalizeValueMatcher } from "../../../../src/server/checker/expect/normalize";
describe("normalizeValueMatcher", () => {
test("normalizes primitive values to equals matcher", () => {
expect(normalizeValueMatcher("stop")).toEqual({ equals: "stop" });
expect(normalizeValueMatcher(1)).toEqual({ equals: 1 });
expect(normalizeValueMatcher(true)).toEqual({ equals: true });
expect(normalizeValueMatcher(null)).toEqual({ equals: null });
});
test("leaves undefined, matcher objects, arrays, and plain objects unchanged", () => {
const matcher = { lte: 5000 };
const array = [1, 2];
const object = { foo: "bar" };
expect(normalizeValueMatcher(undefined)).toBeUndefined();
expect(normalizeValueMatcher(matcher)).toBe(matcher);
expect(normalizeValueMatcher(array)).toBe(array);
expect(normalizeValueMatcher(object)).toBe(object);
});
test("normalizes only selected expect keys", () => {
const expectConfig: Record<string, unknown> = { durationMs: 100, responded: true };
normalizeExpectMatchers(expectConfig, ["durationMs"]);
expect(expectConfig).toEqual({ durationMs: { equals: 100 }, responded: true });
});
});