























@@ -620,4 +620,84 @@ describe("coerceFormValues", () => {
620620const coerced = coerceFormValues(form, schema) as Record<string, unknown>;
621621expect(coerced.flag).toBe(true);
622622});
623+624+it("returns undefined for empty string with minLength constraint", () => {
625+const schema: JsonSchema = {
626+type: "object",
627+properties: {
628+baseUrl: { type: "string", minLength: 1 },
629+},
630+};
631+const form = { baseUrl: "" };
632+const coerced = coerceFormValues(form, schema) as Record<string, unknown>;
633+634+expect(coerced.baseUrl).toBeUndefined();
635+expect("baseUrl" in coerced).toBe(false);
636+});
637+638+it("returns empty string when no minLength constraint", () => {
639+const schema: JsonSchema = {
640+type: "object",
641+properties: {
642+description: { type: "string" },
643+},
644+};
645+const form = { description: "" };
646+const coerced = coerceFormValues(form, schema) as Record<string, unknown>;
647+648+expect(coerced.description).toBe("");
649+expect("description" in coerced).toBe(true);
650+});
651+652+it("returns non-empty string with minLength constraint unchanged", () => {
653+const schema: JsonSchema = {
654+type: "object",
655+properties: {
656+baseUrl: { type: "string", minLength: 1 },
657+},
658+};
659+const form = { baseUrl: "https://api.example.com" };
660+const coerced = coerceFormValues(form, schema) as Record<string, unknown>;
661+662+expect(coerced.baseUrl).toBe("https://api.example.com");
663+});
664+665+it("handles minLength: 0 as no constraint (empty string allowed)", () => {
666+const schema: JsonSchema = {
667+type: "object",
668+properties: {
669+optional: { type: "string", minLength: 0 },
670+},
671+};
672+const form = { optional: "" };
673+const coerced = coerceFormValues(form, schema) as Record<string, unknown>;
674+675+expect(coerced.optional).toBe("");
676+});
677+678+it("clears empty nested string field with minLength in object graph", () => {
679+const schema: JsonSchema = {
680+type: "object",
681+properties: {
682+provider: {
683+type: "object",
684+properties: {
685+baseUrl: { type: "string", minLength: 1 },
686+apiKey: { type: "string" },
687+},
688+},
689+},
690+};
691+const form = {
692+provider: {
693+baseUrl: "",
694+apiKey: "test-key",
695+},
696+};
697+const coerced = coerceFormValues(form, schema) as Record<string, unknown>;
698+const provider = coerced.provider as Record<string, unknown>;
699+700+expect("baseUrl" in provider).toBe(false);
701+expect(provider.apiKey).toBe("test-key");
702+});
623703});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。