32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
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 });
|
|
});
|
|
});
|