From 1c3b1a787ff33a497b8663896883c2c24c017546 Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Mon, 13 May 2024 16:40:50 +0200 Subject: [PATCH] chore: fix the tests --- src/store/formStore.test.ts | 12 ++++++------ src/store/formStore.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) 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