-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow users to skip validation or to fallback to server validat…
…ion (#50) * feat: Allow client validation to be skipped or to fallback to server validation * docs: Document usage of conformValibotMessage
- Loading branch information
Showing
4 changed files
with
158 additions
and
6 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { getValibotConstraint } from "./constraint"; | ||
export { parseWithValibot } from "./parse"; | ||
export { conformValibotMessage, parseWithValibot } from "./parse"; |
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,38 @@ | ||
import { check, object, pipe, string } from "valibot"; | ||
import { describe, expect, test } from "vitest"; | ||
import { conformValibotMessage, parseWithValibot } from "../parse"; | ||
import { createFormData } from "./helpers/FormData"; | ||
|
||
describe("parseWithValibot", () => { | ||
test("should return null for an error field when its error message is skipped", () => { | ||
const schema = object({ | ||
key: pipe( | ||
string(), | ||
check( | ||
(input) => input === "valid", | ||
conformValibotMessage.VALIDATION_SKIPPED, | ||
), | ||
), | ||
}); | ||
const output = parseWithValibot(createFormData("key", "invalid"), { | ||
schema, | ||
}); | ||
expect(output).toMatchObject({ error: { key: null } }); | ||
}); | ||
|
||
test("should return null for the error when any error message is undefined", () => { | ||
const schema = object({ | ||
key: pipe( | ||
string(), | ||
check( | ||
(input) => input === "valid", | ||
conformValibotMessage.VALIDATION_UNDEFINED, | ||
), | ||
), | ||
}); | ||
const output = parseWithValibot(createFormData("key", "invalid"), { | ||
schema, | ||
}); | ||
expect(output).toMatchObject({ error: null }); | ||
}); | ||
}); |