From fa53436ab23c2f64558aedd5e7eedc077044e452 Mon Sep 17 00:00:00 2001 From: BluJ Date: Mon, 3 Apr 2023 15:40:13 -0600 Subject: [PATCH] chore: Add the rest of the config builder test --- lib/config/builder/index.test.ts | 44 ++++++++++++++++++++++++++++++++ lib/config/builder/list.ts | 12 +++------ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/lib/config/builder/index.test.ts b/lib/config/builder/index.test.ts index 3f034bc..ab7660d 100644 --- a/lib/config/builder/index.test.ts +++ b/lib/config/builder/index.test.ts @@ -158,3 +158,47 @@ describe("values", () => { testOutput()(null); }); }); + +describe("Builder List", () => { + test("obj", () => { + const value = Value.list( + List.obj( + { + name: "test", + }, + { + spec: Config.of({ test: Value.boolean({ name: "test" }) }), + } + ) + ); + const validator = value.validator(); + validator.unsafeCast([{ test: true }]); + testOutput()(null); + }); + test("string", () => { + const value = Value.list( + List.string( + { + name: "test", + }, + {} + ) + ); + const validator = value.validator(); + validator.unsafeCast(["test", "text"]); + testOutput()(null); + }); + test("number", () => { + const value = Value.list( + List.number( + { + name: "test", + }, + { integral: true } + ) + ); + const validator = value.validator(); + validator.unsafeCast([12, 45]); + testOutput()(null); + }); +}); diff --git a/lib/config/builder/list.ts b/lib/config/builder/list.ts index b398a48..970e6bf 100644 --- a/lib/config/builder/list.ts +++ b/lib/config/builder/list.ts @@ -1,12 +1,6 @@ import { BuilderExtract, IBuilder } from "./builder"; import { Config } from "./config"; -import { - InputSpec, - ListValueSpecNumber, - ListValueSpecString, - UniqueBy, - ValueSpecList, -} from "../config-types"; +import { InputSpec, ListValueSpecNumber, ListValueSpecString, UniqueBy, ValueSpecList } from "../config-types"; import { guardAll } from "../../util"; /** * Used as a subtype of Value.list @@ -102,7 +96,8 @@ export class List extends IBuilder { name: string; description?: string | null; warning?: string | null; - default: Record[]; + /** Default [] */ + default?: Record[]; /** Default = "(\*,\*)" */ range?: string; }, @@ -123,6 +118,7 @@ export class List extends IBuilder { }; const value = { spec, + default: [], ...a, }; return new List({