feat: add application productivity foundations
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { useForm } from "../src/index.ts";
|
||||
|
||||
test("form state binds fields, validates, submits and resets", async () => {
|
||||
const form = useForm({ name: "", active: false }, (value) => ({
|
||||
name: value.name ? undefined : "Required",
|
||||
}));
|
||||
form.field("name").onInput({ value: "Ada" });
|
||||
form.field("active").onInput({ checked: true });
|
||||
expect(form.dirty.get()).toBe(true);
|
||||
expect(await form.submit(async (value) => value.name)).toBe("Ada");
|
||||
form.reset();
|
||||
expect(form.values.get()).toEqual({ name: "", active: false });
|
||||
});
|
||||
Reference in New Issue
Block a user