Skip to content

Commit cb2eec6

Browse files
committed
Merge commit 'refs/pull/286/merge' of github.com:ciscoheat/sveltekit-superforms
2 parents 865251b + b56f569 commit cb2eec6

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/index.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ test('Optional values', async () => {
219219
expect(output.errors).toStrictEqual({});
220220
});
221221

222+
test('Branded values', async () => {
223+
const schema = z.object({
224+
name: z.string().brand('name'),
225+
});
226+
227+
const data = new FormData();
228+
data.append('name', 'Name');
229+
const output = await superValidate(data, schema);
230+
expect(output.valid).equals(true);
231+
expect(output.message).toBeUndefined();
232+
expect(output.data.name).equals('Name');
233+
expect(output.errors).toStrictEqual({});
234+
});
235+
222236
describe('Default values', () => {
223237
test('With a partial entity', async () => {
224238
const now = new Date();
@@ -801,7 +815,7 @@ test('Passthrough validation', async () => {
801815
});
802816
});
803817

804-
test.only('Preprocessed fields', async () => {
818+
test('Preprocessed fields', async () => {
805819
const schema = z.object({
806820
tristate: z.preprocess(
807821
(value) => (value === undefined ? undefined : Boolean(value)),

src/lib/superValidate.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { traversePath } from './traversal.js';
2424
import type {
2525
z,
2626
AnyZodObject,
27+
ZodBranded,
28+
ZodTypeAny,
2729
ZodNumber,
2830
ZodLiteral,
2931
ZodNativeEnum,
@@ -194,7 +196,10 @@ function formDataToValidation<T extends AnyZodObject>(
194196
typeInfo: ZodTypeInfo
195197
): unknown {
196198
const newValue = valueOrDefault(value, false, true, typeInfo);
197-
const zodType = typeInfo.zodType;
199+
const zodType: ZodTypeAny =
200+
typeInfo.zodType._def.typeName === 'ZodBranded'
201+
? (typeInfo.zodType as ZodBranded<any, any>).unwrap()
202+
: typeInfo.zodType;
198203

199204
// If the value was empty, it now contains the default value,
200205
// so it can be returned immediately, unless it's boolean, which

0 commit comments

Comments
 (0)