@engervall/shared
Advanced tools
Comparing version 1.0.33 to 1.0.34
import type { ZodError } from 'zod'; | ||
export declare function formatZodError(zodError: ZodError, modelName: string): string; | ||
export declare function formatZodError(zodError: ZodError, modelName?: string): string; |
@@ -13,4 +13,8 @@ "use strict"; | ||
}); | ||
if (!modelName) { | ||
return `[${name}] | ||
${message}`; | ||
} | ||
return `[${name} for "${modelName}"] | ||
${message}`; | ||
} |
@@ -14,2 +14,10 @@ "use strict"; | ||
const Options = zod_1.z.union([zod_1.z.literal('option-1'), zod_1.z.literal('option-2')]); | ||
it('should allow omitting the model name', () => { | ||
const invalidPerson = Person.safeParse({ name: 1 }); | ||
if (invalidPerson.success) { | ||
fail("Shouldn't reach this point"); | ||
} | ||
const result = (0, format_zod_error_1.formatZodError)(invalidPerson.error); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
it('should format a ZodError for a union', () => { | ||
@@ -16,0 +24,0 @@ const invalidOptions = Options.safeParse('not-an-option'); |
{ | ||
"name": "@engervall/shared", | ||
"version": "1.0.33", | ||
"version": "1.0.34", | ||
"main": "dist/index.js", | ||
@@ -27,3 +27,3 @@ "repository": "git@github.com:erikengervall/gigalib.git", | ||
}, | ||
"gitHead": "06f22db91d1011b349f2fbb20f2454343f3fdebd" | ||
"gitHead": "f57081681d0aecdd158478be05f6cda2a6ea9d2b" | ||
} |
@@ -15,2 +15,13 @@ import { z } from 'zod'; | ||
it('should allow omitting the model name', () => { | ||
const invalidPerson = Person.safeParse({ name: 1 }); | ||
if (invalidPerson.success) { | ||
fail("Shouldn't reach this point"); | ||
} | ||
const result = formatZodError(invalidPerson.error); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
it('should format a ZodError for a union', () => { | ||
@@ -17,0 +28,0 @@ const invalidOptions = Options.safeParse('not-an-option'); |
@@ -16,3 +16,3 @@ import type { ZodError } from 'zod'; | ||
*/ | ||
modelName: string, | ||
modelName?: string, | ||
) { | ||
@@ -27,4 +27,9 @@ const { message, name } = fromZodError(zodError, { | ||
if (!modelName) { | ||
return `[${name}] | ||
${message}`; | ||
} | ||
return `[${name} for "${modelName}"] | ||
${message}`; | ||
} |
Sorry, the diff of this file is not supported yet
372469
8306