-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: initialize advanced fields with empty values
fixes #52
- Loading branch information
1 parent
5d00dca
commit 67e8ab5
Showing
7 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { formAtom, useFormValues } from "form-atoms"; | ||
import { describe, expect, it } from "vitest"; | ||
import { z } from "zod"; | ||
|
||
import { arrayField } from "./arrayField"; | ||
|
||
const elementSchema = z.string(); | ||
|
||
describe("arrayField()", () => { | ||
it("is initialized as empty string", () => { | ||
const classic = arrayField({ elementSchema }); | ||
const explicitUndefined = arrayField({ elementSchema, value: undefined }); | ||
|
||
const form = formAtom({ classic, explicitUndefined }); | ||
const { result } = renderHook(() => useFormValues(form)); | ||
|
||
expect(result.current).toEqual({ | ||
classic: [], | ||
explicitUndefined: [], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { formAtom, useFormValues } from "form-atoms"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { filesField } from "./filesField"; | ||
|
||
describe("filesField()", () => { | ||
it("is initialized as empty string", () => { | ||
const classic = filesField(); | ||
const explicitUndefined = filesField({ value: undefined }); | ||
|
||
const form = formAtom({ classic, explicitUndefined }); | ||
const { result } = renderHook(() => useFormValues(form)); | ||
|
||
expect(result.current).toEqual({ | ||
classic: [], | ||
explicitUndefined: [], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { renderHook } from "@testing-library/react"; | ||
import { formAtom, useFormValues } from "form-atoms"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { textField } from "./textField"; | ||
|
||
describe("textField()", () => { | ||
it("is initialized as empty string", () => { | ||
const classic = textField(); | ||
const explicitUndefined = textField({ value: undefined }); | ||
|
||
const form = formAtom({ classic, explicitUndefined }); | ||
const { result } = renderHook(() => useFormValues(form)); | ||
|
||
expect(result.current).toEqual({ | ||
classic: "", | ||
explicitUndefined: "", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters