feat: ValueMatcher 支持 primitive 原始值简写,等价于 { equals: value }
This commit is contained in:
31
tests/server/checker/expect/normalize.test.ts
Normal file
31
tests/server/checker/expect/normalize.test.ts
Normal 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 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user