@hookform/resolvers 2.9.11 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/ajv/dist/ajv.d.ts +2 -2
- package/ajv/dist/ajv.js +1 -7
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.mjs +1 -7
- package/ajv/dist/ajv.modern.mjs +2 -0
- package/ajv/dist/ajv.modern.mjs.map +1 -0
- package/ajv/dist/ajv.module.js +1 -7
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js +1 -7
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/index.d.ts +2 -2
- package/ajv/dist/types.d.ts +5 -5
- package/ajv/package.json +3 -1
- package/ajv/src/__tests__/Form-native-validation.tsx +5 -9
- package/ajv/src/__tests__/Form.tsx +4 -6
- package/ajv/src/__tests__/__fixtures__/data.ts +3 -4
- package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +83 -83
- package/ajv/src/ajv.ts +28 -24
- package/class-validator/dist/class-validator.d.ts +2 -2
- package/class-validator/dist/class-validator.js +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.mjs +1 -1
- package/class-validator/dist/class-validator.modern.mjs +2 -0
- package/class-validator/dist/class-validator.modern.mjs.map +1 -0
- package/class-validator/dist/class-validator.module.js +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/index.d.ts +2 -2
- package/class-validator/dist/types.d.ts +12 -9
- package/class-validator/src/__tests__/Form-native-validation.tsx +5 -9
- package/class-validator/src/__tests__/Form.tsx +4 -6
- package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +102 -67
- package/class-validator/src/__tests__/class-validator.ts +66 -6
- package/class-validator/src/class-validator.ts +6 -4
- package/class-validator/src/types.ts +7 -8
- package/computed-types/dist/computed-types.d.ts +2 -2
- package/computed-types/dist/computed-types.js +1 -1
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.mjs +1 -1
- package/computed-types/dist/computed-types.modern.mjs +2 -0
- package/computed-types/dist/computed-types.modern.mjs.map +1 -0
- package/computed-types/dist/computed-types.module.js +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/dist/index.d.ts +2 -2
- package/computed-types/dist/types.d.ts +2 -2
- package/computed-types/src/__tests__/Form-native-validation.tsx +5 -9
- package/computed-types/src/__tests__/Form.tsx +4 -6
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +21 -21
- package/computed-types/src/__tests__/computed-types.ts +16 -0
- package/computed-types/src/computed-types.ts +12 -5
- package/dist/index.d.ts +2 -2
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +1 -1
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/dist/toNestError.d.ts +2 -2
- package/dist/validateFieldsNatively.d.ts +2 -2
- package/io-ts/dist/arrayToPath.d.ts +3 -3
- package/io-ts/dist/errorsToRecord.d.ts +5 -5
- package/io-ts/dist/index.d.ts +2 -2
- package/io-ts/dist/io-ts.d.ts +2 -2
- package/io-ts/dist/io-ts.js +1 -1
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs +2 -0
- package/io-ts/dist/io-ts.modern.mjs.map +1 -0
- package/io-ts/dist/io-ts.module.js +1 -1
- package/io-ts/dist/io-ts.module.js.map +1 -1
- package/io-ts/dist/io-ts.umd.js +1 -1
- package/io-ts/dist/io-ts.umd.js.map +1 -1
- package/io-ts/dist/types.d.ts +7 -7
- package/io-ts/src/__tests__/Form-native-validation.tsx +5 -9
- package/io-ts/src/__tests__/Form.tsx +4 -6
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +28 -28
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/joi/dist/index.d.ts +2 -2
- package/joi/dist/joi.d.ts +2 -2
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/{joi.modern.js → joi.modern.mjs} +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -0
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/dist/types.d.ts +5 -5
- package/joi/src/__tests__/Form-native-validation.tsx +5 -9
- package/joi/src/__tests__/Form.tsx +4 -6
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +87 -87
- package/joi/src/__tests__/joi.ts +8 -8
- package/nope/dist/index.d.ts +2 -2
- package/nope/dist/nope.d.ts +2 -2
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/{nope.modern.js → nope.modern.mjs} +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -0
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/dist/types.d.ts +9 -9
- package/nope/src/__tests__/Form-native-validation.tsx +5 -9
- package/nope/src/__tests__/Form.tsx +4 -6
- package/nope/src/__tests__/__snapshots__/nope.ts.snap +15 -15
- package/nope/src/__tests__/nope.ts +1 -1
- package/package.json +74 -44
- package/superstruct/dist/index.d.ts +2 -2
- package/superstruct/dist/superstruct.d.ts +2 -2
- package/superstruct/dist/superstruct.js +1 -1
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.mjs +1 -1
- package/superstruct/dist/superstruct.modern.mjs +2 -0
- package/superstruct/dist/superstruct.modern.mjs.map +1 -0
- package/superstruct/dist/superstruct.module.js +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/dist/types.d.ts +11 -5
- package/superstruct/src/__tests__/Form-native-validation.tsx +5 -9
- package/superstruct/src/__tests__/Form.tsx +4 -6
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +19 -19
- package/superstruct/src/__tests__/superstruct.ts +13 -0
- package/superstruct/src/superstruct.ts +4 -3
- package/superstruct/src/types.ts +8 -5
- package/typanion/dist/index.d.ts +2 -2
- package/typanion/dist/typanion.d.ts +2 -2
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/{typanion.modern.js → typanion.modern.mjs} +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -0
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/dist/types.d.ts +9 -9
- package/typanion/src/__tests__/Form-native-validation.tsx +7 -10
- package/typanion/src/__tests__/Form.tsx +9 -7
- package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +22 -22
- package/typanion/src/__tests__/typanion.ts +11 -7
- package/typanion/src/typanion.ts +1 -1
- package/typebox/dist/index.d.ts +2 -0
- package/typebox/dist/typebox.d.ts +2 -0
- package/typebox/dist/typebox.js +2 -0
- package/typebox/dist/typebox.js.map +1 -0
- package/typebox/dist/typebox.mjs +2 -0
- package/typebox/dist/typebox.modern.mjs +2 -0
- package/typebox/dist/typebox.modern.mjs.map +1 -0
- package/typebox/dist/typebox.module.js +2 -0
- package/typebox/dist/typebox.module.js.map +1 -0
- package/typebox/dist/typebox.umd.js +2 -0
- package/typebox/dist/typebox.umd.js.map +1 -0
- package/typebox/dist/types.d.ts +3 -0
- package/typebox/package.json +18 -0
- package/typebox/src/__tests__/Form-native-validation.tsx +83 -0
- package/typebox/src/__tests__/Form.tsx +54 -0
- package/typebox/src/__tests__/__fixtures__/data.ts +84 -0
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +190 -0
- package/typebox/src/__tests__/typebox.ts +34 -0
- package/typebox/src/index.ts +2 -0
- package/typebox/src/typebox.ts +64 -0
- package/typebox/src/types.ts +10 -0
- package/vest/dist/index.d.ts +2 -2
- package/vest/dist/types.d.ts +8 -8
- package/vest/dist/vest.d.ts +2 -2
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/{vest.modern.js → vest.modern.mjs} +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -0
- package/vest/dist/vest.module.js.map +1 -1
- package/vest/dist/vest.umd.js.map +1 -1
- package/vest/src/__tests__/Form-native-validation.tsx +5 -9
- package/vest/src/__tests__/Form.tsx +6 -10
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +47 -47
- package/yup/dist/index.d.ts +2 -2
- package/yup/dist/types.d.ts +15 -9
- package/yup/dist/yup.d.ts +2 -2
- package/yup/dist/yup.js +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.mjs +1 -1
- package/yup/dist/yup.modern.mjs +2 -0
- package/yup/dist/yup.modern.mjs.map +1 -0
- package/yup/dist/yup.module.js +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/Form-native-validation.tsx +5 -9
- package/yup/src/__tests__/Form.tsx +4 -6
- package/yup/src/__tests__/__fixtures__/data.ts +2 -3
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +100 -87
- package/yup/src/__tests__/yup.ts +49 -18
- package/yup/src/types.ts +14 -11
- package/yup/src/yup.ts +1 -1
- package/zod/dist/index.d.ts +2 -2
- package/zod/dist/types.d.ts +13 -13
- package/zod/dist/zod.d.ts +2 -2
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +2 -0
- package/zod/dist/zod.modern.mjs.map +1 -0
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/Form-native-validation.tsx +5 -9
- package/zod/src/__tests__/Form.tsx +4 -6
- package/zod/src/__tests__/__snapshots__/zod.ts.snap +120 -120
- package/zod/src/__tests__/zod.ts +19 -7
- package/zod/src/types.ts +2 -6
- package/zod/src/zod.ts +27 -27
- package/ajv/dist/ajv.modern.js +0 -8
- package/ajv/dist/ajv.modern.js.map +0 -1
- package/class-validator/dist/class-validator.modern.js +0 -2
- package/class-validator/dist/class-validator.modern.js.map +0 -1
- package/computed-types/dist/computed-types.modern.js +0 -2
- package/computed-types/dist/computed-types.modern.js.map +0 -1
- package/io-ts/dist/io-ts.modern.js +0 -2
- package/io-ts/dist/io-ts.modern.js.map +0 -1
- package/joi/dist/joi.modern.js.map +0 -1
- package/nope/dist/nope.modern.js.map +0 -1
- package/superstruct/dist/superstruct.modern.js +0 -2
- package/superstruct/dist/superstruct.modern.js.map +0 -1
- package/typanion/dist/typanion.modern.js.map +0 -1
- package/vest/dist/vest.modern.js.map +0 -1
- package/yup/dist/yup.modern.js +0 -2
- package/yup/dist/yup.modern.js.map +0 -1
- package/zod/dist/zod.modern.js +0 -2
- package/zod/dist/zod.modern.js.map +0 -1
package/zod/dist/zod.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e
|
|
1
|
+
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react-hook-form"),require("@hookform/resolvers")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers"],e):e((r||self).hookformResolversZod={},r.ReactHookForm,r.hookformResolvers)}(this,function(r,e,o){var n=function(r,o){for(var n={};r.length;){var s=r[0],t=s.code,i=s.message,a=s.path.join(".");if(!n[a])if("unionErrors"in s){var u=s.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:t};if("unionErrors"in s&&s.unionErrors.forEach(function(e){return e.errors.forEach(function(e){return r.push(e)})}),o){var f=n[a].types,c=f&&f[s.code];n[a]=e.appendErrors(a,o,n,t,c?[].concat(c,s.message):s.message)}r.shift()}return n};r.zodResolver=function(r,e,s){return void 0===s&&(s={}),function(t,i,a){try{return Promise.resolve(function(n,i){try{var u=Promise.resolve(r["sync"===s.mode?"parse":"parseAsync"](t,e)).then(function(r){return a.shouldUseNativeValidation&&o.validateFieldsNatively({},a),{errors:{},values:s.raw?t:r}})}catch(r){return i(r)}return u&&u.then?u.then(void 0,i):u}(0,function(r){if(function(r){return null!=r.errors}(r))return{values:{},errors:o.toNestError(n(r.errors,!a.shouldUseNativeValidation&&"all"===a.criteriaMode),a)};throw r}))}catch(r){return Promise.reject(r)}}}});
|
|
2
2
|
//# sourceMappingURL=zod.umd.js.map
|
package/zod/dist/zod.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.umd.js","sources":["../src/zod.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"zod.umd.js","sources":["../src/zod.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { z, ZodError } from 'zod';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError => error.errors != null;\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","_path","path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","mode","then","data","shouldUseNativeValidation","validateFieldsNatively","raw","_catch","isZodError","toNestError","criteriaMode","reject"],"mappings":"wXAKA,IAEMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAA,EACpCF,EAAUG,QAAU,CACzB,IAAMC,EAAQJ,EAAU,GAChBK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,KAAK,KAExB,IAAKP,EAAOK,GACV,GAAI,gBAAiBH,EAAO,CAC1B,IAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOK,GAAS,CACdD,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAEpB,MACCH,EAAOK,GAAS,CAAED,QAAAA,EAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAAQ,SAACH,GACzB,OAAAA,EAAWR,OAAOW,QAAQ,SAACC,GAAC,OAAKd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EAAAA,aACdX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAUoB,OACX,CAED,OAAOlB,CACT,gBAGE,SAACmB,EAAQC,EAAeC,GACjBC,YADiBD,IAAAA,IAAAA,EAAkB,IACnCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAAA,SAFlBC,GAMN,OAFAL,EAAQM,2BAA6BC,EAAsBA,uBAAC,GAAIP,GAEzD,CACLxB,OAAQ,CAAA,EACRsB,OAAQD,EAAgBW,IAAMV,EAASO,EACvC,4DAXuBI,CACvB,EAWK/B,SAAAA,GACP,GAnEa,SAACA,GAAkC,OAAgB,MAAhBA,EAAMF,MAAc,CAmEhEkC,CAAWhC,GACb,MAAO,CACLoB,OAAQ,CAAA,EACRtB,OAAQmC,EAAWA,YACjBtC,EACEK,EAAMF,QACLwB,EAAQM,2BACkB,QAAzBN,EAAQY,cAEZZ,IAKN,MAAMtB,CACP,GACH,CAAC,MAAAU,GAAA,OAAAa,QAAAY,OAAAzB,EAAA,CAAA,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useForm } from 'react-hook-form';
|
|
3
|
-
import {
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
4
|
import user from '@testing-library/user-event';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { zodResolver } from '..';
|
|
@@ -37,7 +37,7 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
test("form's native validation with Zod", async () => {
|
|
40
|
-
const handleSubmit =
|
|
40
|
+
const handleSubmit = vi.fn();
|
|
41
41
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
42
42
|
|
|
43
43
|
// username
|
|
@@ -54,9 +54,7 @@ test("form's native validation with Zod", async () => {
|
|
|
54
54
|
expect(passwordField.validity.valid).toBe(true);
|
|
55
55
|
expect(passwordField.validationMessage).toBe('');
|
|
56
56
|
|
|
57
|
-
await
|
|
58
|
-
user.click(screen.getByText(/submit/i));
|
|
59
|
-
});
|
|
57
|
+
await user.click(screen.getByText(/submit/i));
|
|
60
58
|
|
|
61
59
|
// username
|
|
62
60
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -68,10 +66,8 @@ test("form's native validation with Zod", async () => {
|
|
|
68
66
|
expect(passwordField.validity.valid).toBe(false);
|
|
69
67
|
expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
|
|
70
68
|
|
|
71
|
-
await
|
|
72
|
-
|
|
73
|
-
user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
74
|
-
});
|
|
69
|
+
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
|
70
|
+
await user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
75
71
|
|
|
76
72
|
// username
|
|
77
73
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, screen
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import user from '@testing-library/user-event';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -39,14 +39,12 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
test("form's validation with Zod and TypeScript's integration", async () => {
|
|
42
|
-
const handleSubmit =
|
|
42
|
+
const handleSubmit = vi.fn();
|
|
43
43
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
44
44
|
|
|
45
|
-
expect(screen.queryAllByRole(
|
|
45
|
+
expect(screen.queryAllByRole('alert')).toHaveLength(0);
|
|
46
46
|
|
|
47
|
-
await
|
|
48
|
-
user.click(screen.getByText(/submit/i));
|
|
49
|
-
});
|
|
47
|
+
await user.click(screen.getByText(/submit/i));
|
|
50
48
|
|
|
51
49
|
expect(screen.getByText(/username field is required/i)).toBeInTheDocument();
|
|
52
50
|
expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
|
|
@@ -1,238 +1,238 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`zodResolver should return a single error from zodResolver when validation fails 1`] = `
|
|
4
|
-
|
|
5
|
-
"errors":
|
|
6
|
-
"accessToken":
|
|
3
|
+
exports[`zodResolver > should return a single error from zodResolver when validation fails 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"accessToken": {
|
|
7
7
|
"message": "Required",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "invalid_type",
|
|
10
10
|
},
|
|
11
|
-
"birthYear":
|
|
11
|
+
"birthYear": {
|
|
12
12
|
"message": "Expected number, received string",
|
|
13
13
|
"ref": undefined,
|
|
14
14
|
"type": "invalid_type",
|
|
15
15
|
},
|
|
16
|
-
"dateStr":
|
|
16
|
+
"dateStr": {
|
|
17
17
|
"message": "Required",
|
|
18
18
|
"ref": undefined,
|
|
19
19
|
"type": "invalid_type",
|
|
20
20
|
},
|
|
21
|
-
"email":
|
|
21
|
+
"email": {
|
|
22
22
|
"message": "Invalid email",
|
|
23
|
-
"ref":
|
|
23
|
+
"ref": {
|
|
24
24
|
"name": "email",
|
|
25
25
|
},
|
|
26
26
|
"type": "invalid_string",
|
|
27
27
|
},
|
|
28
|
-
"enabled":
|
|
28
|
+
"enabled": {
|
|
29
29
|
"message": "Required",
|
|
30
30
|
"ref": undefined,
|
|
31
31
|
"type": "invalid_type",
|
|
32
32
|
},
|
|
33
|
-
"like":
|
|
34
|
-
|
|
35
|
-
"id":
|
|
33
|
+
"like": [
|
|
34
|
+
{
|
|
35
|
+
"id": {
|
|
36
36
|
"message": "Expected number, received string",
|
|
37
37
|
"ref": undefined,
|
|
38
38
|
"type": "invalid_type",
|
|
39
39
|
},
|
|
40
|
-
"name":
|
|
40
|
+
"name": {
|
|
41
41
|
"message": "Required",
|
|
42
42
|
"ref": undefined,
|
|
43
43
|
"type": "invalid_type",
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
],
|
|
47
|
-
"password":
|
|
47
|
+
"password": {
|
|
48
48
|
"message": "One uppercase character",
|
|
49
|
-
"ref":
|
|
49
|
+
"ref": {
|
|
50
50
|
"name": "password",
|
|
51
51
|
},
|
|
52
52
|
"type": "invalid_string",
|
|
53
53
|
},
|
|
54
|
-
"repeatPassword":
|
|
54
|
+
"repeatPassword": {
|
|
55
55
|
"message": "Required",
|
|
56
56
|
"ref": undefined,
|
|
57
57
|
"type": "invalid_type",
|
|
58
58
|
},
|
|
59
|
-
"tags":
|
|
59
|
+
"tags": {
|
|
60
60
|
"message": "Required",
|
|
61
61
|
"ref": undefined,
|
|
62
62
|
"type": "invalid_type",
|
|
63
63
|
},
|
|
64
|
-
"url":
|
|
64
|
+
"url": {
|
|
65
65
|
"message": "Custom error url",
|
|
66
66
|
"ref": undefined,
|
|
67
67
|
"type": "invalid_string",
|
|
68
68
|
},
|
|
69
|
-
"username":
|
|
69
|
+
"username": {
|
|
70
70
|
"message": "Required",
|
|
71
|
-
"ref":
|
|
71
|
+
"ref": {
|
|
72
72
|
"name": "username",
|
|
73
73
|
},
|
|
74
74
|
"type": "invalid_type",
|
|
75
75
|
},
|
|
76
76
|
},
|
|
77
|
-
"values":
|
|
77
|
+
"values": {},
|
|
78
78
|
}
|
|
79
79
|
`;
|
|
80
80
|
|
|
81
|
-
exports[`zodResolver should return a single error from zodResolver with \`mode: sync\` when validation fails 1`] = `
|
|
82
|
-
|
|
83
|
-
"errors":
|
|
84
|
-
"accessToken":
|
|
81
|
+
exports[`zodResolver > should return a single error from zodResolver with \`mode: sync\` when validation fails 1`] = `
|
|
82
|
+
{
|
|
83
|
+
"errors": {
|
|
84
|
+
"accessToken": {
|
|
85
85
|
"message": "Required",
|
|
86
86
|
"ref": undefined,
|
|
87
87
|
"type": "invalid_type",
|
|
88
88
|
},
|
|
89
|
-
"birthYear":
|
|
89
|
+
"birthYear": {
|
|
90
90
|
"message": "Expected number, received string",
|
|
91
91
|
"ref": undefined,
|
|
92
92
|
"type": "invalid_type",
|
|
93
93
|
},
|
|
94
|
-
"dateStr":
|
|
94
|
+
"dateStr": {
|
|
95
95
|
"message": "Required",
|
|
96
96
|
"ref": undefined,
|
|
97
97
|
"type": "invalid_type",
|
|
98
98
|
},
|
|
99
|
-
"email":
|
|
99
|
+
"email": {
|
|
100
100
|
"message": "Invalid email",
|
|
101
|
-
"ref":
|
|
101
|
+
"ref": {
|
|
102
102
|
"name": "email",
|
|
103
103
|
},
|
|
104
104
|
"type": "invalid_string",
|
|
105
105
|
},
|
|
106
|
-
"enabled":
|
|
106
|
+
"enabled": {
|
|
107
107
|
"message": "Required",
|
|
108
108
|
"ref": undefined,
|
|
109
109
|
"type": "invalid_type",
|
|
110
110
|
},
|
|
111
|
-
"like":
|
|
112
|
-
|
|
113
|
-
"id":
|
|
111
|
+
"like": [
|
|
112
|
+
{
|
|
113
|
+
"id": {
|
|
114
114
|
"message": "Expected number, received string",
|
|
115
115
|
"ref": undefined,
|
|
116
116
|
"type": "invalid_type",
|
|
117
117
|
},
|
|
118
|
-
"name":
|
|
118
|
+
"name": {
|
|
119
119
|
"message": "Required",
|
|
120
120
|
"ref": undefined,
|
|
121
121
|
"type": "invalid_type",
|
|
122
122
|
},
|
|
123
123
|
},
|
|
124
124
|
],
|
|
125
|
-
"password":
|
|
125
|
+
"password": {
|
|
126
126
|
"message": "One uppercase character",
|
|
127
|
-
"ref":
|
|
127
|
+
"ref": {
|
|
128
128
|
"name": "password",
|
|
129
129
|
},
|
|
130
130
|
"type": "invalid_string",
|
|
131
131
|
},
|
|
132
|
-
"repeatPassword":
|
|
132
|
+
"repeatPassword": {
|
|
133
133
|
"message": "Required",
|
|
134
134
|
"ref": undefined,
|
|
135
135
|
"type": "invalid_type",
|
|
136
136
|
},
|
|
137
|
-
"tags":
|
|
137
|
+
"tags": {
|
|
138
138
|
"message": "Required",
|
|
139
139
|
"ref": undefined,
|
|
140
140
|
"type": "invalid_type",
|
|
141
141
|
},
|
|
142
|
-
"url":
|
|
142
|
+
"url": {
|
|
143
143
|
"message": "Custom error url",
|
|
144
144
|
"ref": undefined,
|
|
145
145
|
"type": "invalid_string",
|
|
146
146
|
},
|
|
147
|
-
"username":
|
|
147
|
+
"username": {
|
|
148
148
|
"message": "Required",
|
|
149
|
-
"ref":
|
|
149
|
+
"ref": {
|
|
150
150
|
"name": "username",
|
|
151
151
|
},
|
|
152
152
|
"type": "invalid_type",
|
|
153
153
|
},
|
|
154
154
|
},
|
|
155
|
-
"values":
|
|
155
|
+
"values": {},
|
|
156
156
|
}
|
|
157
157
|
`;
|
|
158
158
|
|
|
159
|
-
exports[`zodResolver should return all the errors from zodResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
160
|
-
|
|
161
|
-
"errors":
|
|
162
|
-
"accessToken":
|
|
159
|
+
exports[`zodResolver > should return all the errors from zodResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
160
|
+
{
|
|
161
|
+
"errors": {
|
|
162
|
+
"accessToken": {
|
|
163
163
|
"message": "Required",
|
|
164
164
|
"ref": undefined,
|
|
165
165
|
"type": "invalid_type",
|
|
166
|
-
"types":
|
|
167
|
-
"invalid_type":
|
|
166
|
+
"types": {
|
|
167
|
+
"invalid_type": [
|
|
168
168
|
"Required",
|
|
169
169
|
"Required",
|
|
170
170
|
],
|
|
171
171
|
"invalid_union": "Invalid input",
|
|
172
172
|
},
|
|
173
173
|
},
|
|
174
|
-
"birthYear":
|
|
174
|
+
"birthYear": {
|
|
175
175
|
"message": "Expected number, received string",
|
|
176
176
|
"ref": undefined,
|
|
177
177
|
"type": "invalid_type",
|
|
178
|
-
"types":
|
|
178
|
+
"types": {
|
|
179
179
|
"invalid_type": "Expected number, received string",
|
|
180
180
|
},
|
|
181
181
|
},
|
|
182
|
-
"dateStr":
|
|
182
|
+
"dateStr": {
|
|
183
183
|
"message": "Required",
|
|
184
184
|
"ref": undefined,
|
|
185
185
|
"type": "invalid_type",
|
|
186
|
-
"types":
|
|
186
|
+
"types": {
|
|
187
187
|
"invalid_type": "Required",
|
|
188
188
|
},
|
|
189
189
|
},
|
|
190
|
-
"email":
|
|
190
|
+
"email": {
|
|
191
191
|
"message": "Invalid email",
|
|
192
|
-
"ref":
|
|
192
|
+
"ref": {
|
|
193
193
|
"name": "email",
|
|
194
194
|
},
|
|
195
195
|
"type": "invalid_string",
|
|
196
|
-
"types":
|
|
196
|
+
"types": {
|
|
197
197
|
"invalid_string": "Invalid email",
|
|
198
198
|
},
|
|
199
199
|
},
|
|
200
|
-
"enabled":
|
|
200
|
+
"enabled": {
|
|
201
201
|
"message": "Required",
|
|
202
202
|
"ref": undefined,
|
|
203
203
|
"type": "invalid_type",
|
|
204
|
-
"types":
|
|
204
|
+
"types": {
|
|
205
205
|
"invalid_type": "Required",
|
|
206
206
|
},
|
|
207
207
|
},
|
|
208
|
-
"like":
|
|
209
|
-
|
|
210
|
-
"id":
|
|
208
|
+
"like": [
|
|
209
|
+
{
|
|
210
|
+
"id": {
|
|
211
211
|
"message": "Expected number, received string",
|
|
212
212
|
"ref": undefined,
|
|
213
213
|
"type": "invalid_type",
|
|
214
|
-
"types":
|
|
214
|
+
"types": {
|
|
215
215
|
"invalid_type": "Expected number, received string",
|
|
216
216
|
},
|
|
217
217
|
},
|
|
218
|
-
"name":
|
|
218
|
+
"name": {
|
|
219
219
|
"message": "Required",
|
|
220
220
|
"ref": undefined,
|
|
221
221
|
"type": "invalid_type",
|
|
222
|
-
"types":
|
|
222
|
+
"types": {
|
|
223
223
|
"invalid_type": "Required",
|
|
224
224
|
},
|
|
225
225
|
},
|
|
226
226
|
},
|
|
227
227
|
],
|
|
228
|
-
"password":
|
|
228
|
+
"password": {
|
|
229
229
|
"message": "One uppercase character",
|
|
230
|
-
"ref":
|
|
230
|
+
"ref": {
|
|
231
231
|
"name": "password",
|
|
232
232
|
},
|
|
233
233
|
"type": "invalid_string",
|
|
234
|
-
"types":
|
|
235
|
-
"invalid_string":
|
|
234
|
+
"types": {
|
|
235
|
+
"invalid_string": [
|
|
236
236
|
"One uppercase character",
|
|
237
237
|
"One lowercase character",
|
|
238
238
|
"One number",
|
|
@@ -240,122 +240,122 @@ Object {
|
|
|
240
240
|
"too_small": "Must be at least 8 characters in length",
|
|
241
241
|
},
|
|
242
242
|
},
|
|
243
|
-
"repeatPassword":
|
|
243
|
+
"repeatPassword": {
|
|
244
244
|
"message": "Required",
|
|
245
245
|
"ref": undefined,
|
|
246
246
|
"type": "invalid_type",
|
|
247
|
-
"types":
|
|
247
|
+
"types": {
|
|
248
248
|
"invalid_type": "Required",
|
|
249
249
|
},
|
|
250
250
|
},
|
|
251
|
-
"tags":
|
|
251
|
+
"tags": {
|
|
252
252
|
"message": "Required",
|
|
253
253
|
"ref": undefined,
|
|
254
254
|
"type": "invalid_type",
|
|
255
|
-
"types":
|
|
255
|
+
"types": {
|
|
256
256
|
"invalid_type": "Required",
|
|
257
257
|
},
|
|
258
258
|
},
|
|
259
|
-
"url":
|
|
259
|
+
"url": {
|
|
260
260
|
"message": "Custom error url",
|
|
261
261
|
"ref": undefined,
|
|
262
262
|
"type": "invalid_string",
|
|
263
|
-
"types":
|
|
263
|
+
"types": {
|
|
264
264
|
"invalid_string": "Custom error url",
|
|
265
265
|
},
|
|
266
266
|
},
|
|
267
|
-
"username":
|
|
267
|
+
"username": {
|
|
268
268
|
"message": "Required",
|
|
269
|
-
"ref":
|
|
269
|
+
"ref": {
|
|
270
270
|
"name": "username",
|
|
271
271
|
},
|
|
272
272
|
"type": "invalid_type",
|
|
273
|
-
"types":
|
|
273
|
+
"types": {
|
|
274
274
|
"invalid_type": "Required",
|
|
275
275
|
},
|
|
276
276
|
},
|
|
277
277
|
},
|
|
278
|
-
"values":
|
|
278
|
+
"values": {},
|
|
279
279
|
}
|
|
280
280
|
`;
|
|
281
281
|
|
|
282
|
-
exports[`zodResolver should return all the errors from zodResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
|
|
283
|
-
|
|
284
|
-
"errors":
|
|
285
|
-
"accessToken":
|
|
282
|
+
exports[`zodResolver > should return all the errors from zodResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
|
|
283
|
+
{
|
|
284
|
+
"errors": {
|
|
285
|
+
"accessToken": {
|
|
286
286
|
"message": "Required",
|
|
287
287
|
"ref": undefined,
|
|
288
288
|
"type": "invalid_type",
|
|
289
|
-
"types":
|
|
290
|
-
"invalid_type":
|
|
289
|
+
"types": {
|
|
290
|
+
"invalid_type": [
|
|
291
291
|
"Required",
|
|
292
292
|
"Required",
|
|
293
293
|
],
|
|
294
294
|
"invalid_union": "Invalid input",
|
|
295
295
|
},
|
|
296
296
|
},
|
|
297
|
-
"birthYear":
|
|
297
|
+
"birthYear": {
|
|
298
298
|
"message": "Expected number, received string",
|
|
299
299
|
"ref": undefined,
|
|
300
300
|
"type": "invalid_type",
|
|
301
|
-
"types":
|
|
301
|
+
"types": {
|
|
302
302
|
"invalid_type": "Expected number, received string",
|
|
303
303
|
},
|
|
304
304
|
},
|
|
305
|
-
"dateStr":
|
|
305
|
+
"dateStr": {
|
|
306
306
|
"message": "Required",
|
|
307
307
|
"ref": undefined,
|
|
308
308
|
"type": "invalid_type",
|
|
309
|
-
"types":
|
|
309
|
+
"types": {
|
|
310
310
|
"invalid_type": "Required",
|
|
311
311
|
},
|
|
312
312
|
},
|
|
313
|
-
"email":
|
|
313
|
+
"email": {
|
|
314
314
|
"message": "Invalid email",
|
|
315
|
-
"ref":
|
|
315
|
+
"ref": {
|
|
316
316
|
"name": "email",
|
|
317
317
|
},
|
|
318
318
|
"type": "invalid_string",
|
|
319
|
-
"types":
|
|
319
|
+
"types": {
|
|
320
320
|
"invalid_string": "Invalid email",
|
|
321
321
|
},
|
|
322
322
|
},
|
|
323
|
-
"enabled":
|
|
323
|
+
"enabled": {
|
|
324
324
|
"message": "Required",
|
|
325
325
|
"ref": undefined,
|
|
326
326
|
"type": "invalid_type",
|
|
327
|
-
"types":
|
|
327
|
+
"types": {
|
|
328
328
|
"invalid_type": "Required",
|
|
329
329
|
},
|
|
330
330
|
},
|
|
331
|
-
"like":
|
|
332
|
-
|
|
333
|
-
"id":
|
|
331
|
+
"like": [
|
|
332
|
+
{
|
|
333
|
+
"id": {
|
|
334
334
|
"message": "Expected number, received string",
|
|
335
335
|
"ref": undefined,
|
|
336
336
|
"type": "invalid_type",
|
|
337
|
-
"types":
|
|
337
|
+
"types": {
|
|
338
338
|
"invalid_type": "Expected number, received string",
|
|
339
339
|
},
|
|
340
340
|
},
|
|
341
|
-
"name":
|
|
341
|
+
"name": {
|
|
342
342
|
"message": "Required",
|
|
343
343
|
"ref": undefined,
|
|
344
344
|
"type": "invalid_type",
|
|
345
|
-
"types":
|
|
345
|
+
"types": {
|
|
346
346
|
"invalid_type": "Required",
|
|
347
347
|
},
|
|
348
348
|
},
|
|
349
349
|
},
|
|
350
350
|
],
|
|
351
|
-
"password":
|
|
351
|
+
"password": {
|
|
352
352
|
"message": "One uppercase character",
|
|
353
|
-
"ref":
|
|
353
|
+
"ref": {
|
|
354
354
|
"name": "password",
|
|
355
355
|
},
|
|
356
356
|
"type": "invalid_string",
|
|
357
|
-
"types":
|
|
358
|
-
"invalid_string":
|
|
357
|
+
"types": {
|
|
358
|
+
"invalid_string": [
|
|
359
359
|
"One uppercase character",
|
|
360
360
|
"One lowercase character",
|
|
361
361
|
"One number",
|
|
@@ -363,63 +363,63 @@ Object {
|
|
|
363
363
|
"too_small": "Must be at least 8 characters in length",
|
|
364
364
|
},
|
|
365
365
|
},
|
|
366
|
-
"repeatPassword":
|
|
366
|
+
"repeatPassword": {
|
|
367
367
|
"message": "Required",
|
|
368
368
|
"ref": undefined,
|
|
369
369
|
"type": "invalid_type",
|
|
370
|
-
"types":
|
|
370
|
+
"types": {
|
|
371
371
|
"invalid_type": "Required",
|
|
372
372
|
},
|
|
373
373
|
},
|
|
374
|
-
"tags":
|
|
374
|
+
"tags": {
|
|
375
375
|
"message": "Required",
|
|
376
376
|
"ref": undefined,
|
|
377
377
|
"type": "invalid_type",
|
|
378
|
-
"types":
|
|
378
|
+
"types": {
|
|
379
379
|
"invalid_type": "Required",
|
|
380
380
|
},
|
|
381
381
|
},
|
|
382
|
-
"url":
|
|
382
|
+
"url": {
|
|
383
383
|
"message": "Custom error url",
|
|
384
384
|
"ref": undefined,
|
|
385
385
|
"type": "invalid_string",
|
|
386
|
-
"types":
|
|
386
|
+
"types": {
|
|
387
387
|
"invalid_string": "Custom error url",
|
|
388
388
|
},
|
|
389
389
|
},
|
|
390
|
-
"username":
|
|
390
|
+
"username": {
|
|
391
391
|
"message": "Required",
|
|
392
|
-
"ref":
|
|
392
|
+
"ref": {
|
|
393
393
|
"name": "username",
|
|
394
394
|
},
|
|
395
395
|
"type": "invalid_type",
|
|
396
|
-
"types":
|
|
396
|
+
"types": {
|
|
397
397
|
"invalid_type": "Required",
|
|
398
398
|
},
|
|
399
399
|
},
|
|
400
400
|
},
|
|
401
|
-
"values":
|
|
401
|
+
"values": {},
|
|
402
402
|
}
|
|
403
403
|
`;
|
|
404
404
|
|
|
405
|
-
exports[`zodResolver should return parsed values from zodResolver with \`mode: sync\` when validation pass 1`] = `
|
|
406
|
-
|
|
407
|
-
"errors":
|
|
408
|
-
"values":
|
|
405
|
+
exports[`zodResolver > should return parsed values from zodResolver with \`mode: sync\` when validation pass 1`] = `
|
|
406
|
+
{
|
|
407
|
+
"errors": {},
|
|
408
|
+
"values": {
|
|
409
409
|
"accessToken": "accessToken",
|
|
410
410
|
"birthYear": 2000,
|
|
411
411
|
"dateStr": 2020-01-01T00:00:00.000Z,
|
|
412
412
|
"email": "john@doe.com",
|
|
413
413
|
"enabled": true,
|
|
414
|
-
"like":
|
|
415
|
-
|
|
414
|
+
"like": [
|
|
415
|
+
{
|
|
416
416
|
"id": 1,
|
|
417
417
|
"name": "name",
|
|
418
418
|
},
|
|
419
419
|
],
|
|
420
420
|
"password": "Password123_",
|
|
421
421
|
"repeatPassword": "Password123_",
|
|
422
|
-
"tags":
|
|
422
|
+
"tags": [
|
|
423
423
|
"tag1",
|
|
424
424
|
"tag2",
|
|
425
425
|
],
|