diff --git a/src/store/formStore.test.ts b/src/store/formStore.test.ts index 5be38ebe..84943702 100644 --- a/src/store/formStore.test.ts +++ b/src/store/formStore.test.ts @@ -4,7 +4,7 @@ import { makeFormEngine } from "./formStore"; describe("Form Engine", () => { it("should update form fields correctly", () => { const onSubmitMock = jest.fn(); - const formEngine = makeFormEngine(onSubmitMock); + const formEngine = makeFormEngine({ onSubmit: onSubmitMock }); // Add fields to the form const field1 = formEngine.addField({ name: "fieldName1" }); @@ -24,7 +24,7 @@ describe("Form Engine", () => { it("should handle field errors correctly", () => { const onSubmitMock = jest.fn(); - const formEngine = makeFormEngine(onSubmitMock); + const formEngine = makeFormEngine({ onSubmit: onSubmitMock }); // Add a field to the form const field1 = formEngine.addField({ name: "fieldName1", @@ -43,7 +43,7 @@ describe("Form Engine", () => { }); it("field errors should prefer field label over field name", () => { const onSubmitMock = jest.fn(); - const formEngine = makeFormEngine(onSubmitMock); + const formEngine = makeFormEngine({ onSubmit: onSubmitMock }); // Add a field to the form const field1 = formEngine.addField({ name: "fieldName1", @@ -63,7 +63,7 @@ describe("Form Engine", () => { }); it("Clears the errors when a value is set", () => { const onSubmitMock = jest.fn(); - const formEngine = makeFormEngine(onSubmitMock); + const formEngine = makeFormEngine({ onSubmit: onSubmitMock }); // Add a field to the form const field1 = formEngine.addField({ name: "fieldName1", @@ -92,7 +92,7 @@ describe("Form Engine", () => { fieldName1: "default1", fieldName2: "default2", }; - const formEngine = makeFormEngine(onSubmitMock, defaultValues); + const formEngine = makeFormEngine({ onSubmit: onSubmitMock, defaultValues }); // Add fields to the form const field1 = formEngine.addField({ name: "fieldName1" }); @@ -114,7 +114,7 @@ describe("Form Engine", () => { const defaultValues = { fieldName1: "default1", }; - const formEngine = makeFormEngine(onSubmitMock, defaultValues); + const formEngine = makeFormEngine({ onSubmit: onSubmitMock, defaultValues }); // Add fields to the form const field1 = formEngine.addField({ name: "fieldName1" }); diff --git a/src/store/formStore.ts b/src/store/formStore.ts index fd0ab601..9746b9d6 100644 --- a/src/store/formStore.ts +++ b/src/store/formStore.ts @@ -131,12 +131,12 @@ export type OnFormSubmit = (values: Record) => void; type makeFormEngineArgs = { onSubmit: OnFormSubmit; onCancel?: () => void; - defaultValues: Record; + defaultValues?: Record; }; export function makeFormEngine({ onSubmit, - defaultValues, + defaultValues = {}, }: makeFormEngineArgs): FormEngine { const formStore: Writable> = writable({ fields: {} }); // Creates helper functions to modify the store immutably