@hookform/resolvers 2.9.11 → 3.0.1
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 +51 -5
- 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
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`typeboxResolver > should return a single error from typeboxResolver when validation fails 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"accessToken": {
|
|
7
|
+
"message": "Expected string",
|
|
8
|
+
"ref": undefined,
|
|
9
|
+
"type": "43",
|
|
10
|
+
},
|
|
11
|
+
"birthYear": {
|
|
12
|
+
"message": "Expected number",
|
|
13
|
+
"ref": undefined,
|
|
14
|
+
"type": "29",
|
|
15
|
+
},
|
|
16
|
+
"dateStr": {
|
|
17
|
+
"message": "Expected Date object",
|
|
18
|
+
"ref": undefined,
|
|
19
|
+
"type": "11",
|
|
20
|
+
},
|
|
21
|
+
"email": {
|
|
22
|
+
"message": "Expected string to match format 'email'",
|
|
23
|
+
"ref": {
|
|
24
|
+
"name": "email",
|
|
25
|
+
},
|
|
26
|
+
"type": "48",
|
|
27
|
+
},
|
|
28
|
+
"enabled": {
|
|
29
|
+
"message": "Expected boolean",
|
|
30
|
+
"ref": undefined,
|
|
31
|
+
"type": "10",
|
|
32
|
+
},
|
|
33
|
+
"like": [
|
|
34
|
+
{
|
|
35
|
+
"id": {
|
|
36
|
+
"message": "Expected number",
|
|
37
|
+
"ref": undefined,
|
|
38
|
+
"type": "29",
|
|
39
|
+
},
|
|
40
|
+
"name": {
|
|
41
|
+
"message": "Expected string",
|
|
42
|
+
"ref": undefined,
|
|
43
|
+
"type": "43",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
"password": {
|
|
48
|
+
"message": "Expected string length greater or equal to 8",
|
|
49
|
+
"ref": {
|
|
50
|
+
"name": "password",
|
|
51
|
+
},
|
|
52
|
+
"type": "44",
|
|
53
|
+
},
|
|
54
|
+
"repeatPassword": {
|
|
55
|
+
"message": "Expected string",
|
|
56
|
+
"ref": undefined,
|
|
57
|
+
"type": "43",
|
|
58
|
+
},
|
|
59
|
+
"tags": {
|
|
60
|
+
"message": "Expected array",
|
|
61
|
+
"ref": undefined,
|
|
62
|
+
"type": "0",
|
|
63
|
+
},
|
|
64
|
+
"username": {
|
|
65
|
+
"message": "Expected string",
|
|
66
|
+
"ref": {
|
|
67
|
+
"name": "username",
|
|
68
|
+
},
|
|
69
|
+
"type": "43",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
"values": {},
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
exports[`typeboxResolver > should return all the errors from typeboxResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
77
|
+
{
|
|
78
|
+
"errors": {
|
|
79
|
+
"accessToken": {
|
|
80
|
+
"message": "Expected string",
|
|
81
|
+
"ref": undefined,
|
|
82
|
+
"type": "43",
|
|
83
|
+
"types": {
|
|
84
|
+
"29": "Expected number",
|
|
85
|
+
"39": "Expected required property",
|
|
86
|
+
"43": "Expected string",
|
|
87
|
+
"53": "Expected value of union",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
"birthYear": {
|
|
91
|
+
"message": "Expected number",
|
|
92
|
+
"ref": undefined,
|
|
93
|
+
"type": "29",
|
|
94
|
+
"types": {
|
|
95
|
+
"29": "Expected number",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
"dateStr": {
|
|
99
|
+
"message": "Expected Date object",
|
|
100
|
+
"ref": undefined,
|
|
101
|
+
"type": "11",
|
|
102
|
+
"types": {
|
|
103
|
+
"11": "Expected Date object",
|
|
104
|
+
"39": "Expected required property",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
"email": {
|
|
108
|
+
"message": "Expected string to match format 'email'",
|
|
109
|
+
"ref": {
|
|
110
|
+
"name": "email",
|
|
111
|
+
},
|
|
112
|
+
"type": "48",
|
|
113
|
+
"types": {
|
|
114
|
+
"48": "Expected string to match format 'email'",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
"enabled": {
|
|
118
|
+
"message": "Expected boolean",
|
|
119
|
+
"ref": undefined,
|
|
120
|
+
"type": "10",
|
|
121
|
+
"types": {
|
|
122
|
+
"10": "Expected boolean",
|
|
123
|
+
"39": "Expected required property",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
"like": [
|
|
127
|
+
{
|
|
128
|
+
"id": {
|
|
129
|
+
"message": "Expected number",
|
|
130
|
+
"ref": undefined,
|
|
131
|
+
"type": "29",
|
|
132
|
+
"types": {
|
|
133
|
+
"29": "Expected number",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
"name": {
|
|
137
|
+
"message": "Expected string",
|
|
138
|
+
"ref": undefined,
|
|
139
|
+
"type": "43",
|
|
140
|
+
"types": {
|
|
141
|
+
"39": "Expected required property",
|
|
142
|
+
"43": "Expected string",
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
"password": {
|
|
148
|
+
"message": "Expected string length greater or equal to 8",
|
|
149
|
+
"ref": {
|
|
150
|
+
"name": "password",
|
|
151
|
+
},
|
|
152
|
+
"type": "44",
|
|
153
|
+
"types": {
|
|
154
|
+
"44": "Expected string length greater or equal to 8",
|
|
155
|
+
"46": "Expected string to match pattern ^(.*[A-Za-z\\\\d].*)$",
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
"repeatPassword": {
|
|
159
|
+
"message": "Expected string",
|
|
160
|
+
"ref": undefined,
|
|
161
|
+
"type": "43",
|
|
162
|
+
"types": {
|
|
163
|
+
"39": "Expected required property",
|
|
164
|
+
"43": "Expected string",
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
"tags": {
|
|
168
|
+
"message": "Expected array",
|
|
169
|
+
"ref": undefined,
|
|
170
|
+
"type": "0",
|
|
171
|
+
"types": {
|
|
172
|
+
"0": "Expected array",
|
|
173
|
+
"39": "Expected required property",
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
"username": {
|
|
177
|
+
"message": "Expected string",
|
|
178
|
+
"ref": {
|
|
179
|
+
"name": "username",
|
|
180
|
+
},
|
|
181
|
+
"type": "43",
|
|
182
|
+
"types": {
|
|
183
|
+
"39": "Expected required property",
|
|
184
|
+
"43": "Expected string",
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
"values": {},
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { typeboxResolver } from '..';
|
|
2
|
+
import { schema, validData, invalidData, fields } from './__fixtures__/data';
|
|
3
|
+
|
|
4
|
+
const shouldUseNativeValidation = false;
|
|
5
|
+
|
|
6
|
+
describe('typeboxResolver', () => {
|
|
7
|
+
it('should return a single error from typeboxResolver when validation fails', async () => {
|
|
8
|
+
const result = await typeboxResolver(schema)(invalidData, undefined, {
|
|
9
|
+
fields,
|
|
10
|
+
shouldUseNativeValidation,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
expect(result).toMatchSnapshot();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return all the errors from typeboxResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
|
|
17
|
+
const result = await typeboxResolver(schema)(invalidData, undefined, {
|
|
18
|
+
fields,
|
|
19
|
+
criteriaMode: 'all',
|
|
20
|
+
shouldUseNativeValidation,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(result).toMatchSnapshot();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should validate with success', async () => {
|
|
27
|
+
const result = await typeboxResolver(schema)(validData, undefined, {
|
|
28
|
+
fields,
|
|
29
|
+
shouldUseNativeValidation,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(result).toEqual({ errors: {}, values: validData });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';
|
|
2
|
+
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
|
+
import type { Resolver } from './types';
|
|
4
|
+
import { Value, ValueError } from '@sinclair/typebox/value';
|
|
5
|
+
|
|
6
|
+
const parseErrorSchema = (
|
|
7
|
+
_errors: ValueError[],
|
|
8
|
+
validateAllFieldCriteria: boolean,
|
|
9
|
+
) => {
|
|
10
|
+
const errors: Record<string, FieldError> = {};
|
|
11
|
+
for (; _errors.length; ) {
|
|
12
|
+
const error = _errors[0];
|
|
13
|
+
const { type, message, path } = error;
|
|
14
|
+
const _path = path.substring(1).replace(/\//g, '.');
|
|
15
|
+
|
|
16
|
+
if (!errors[_path]) {
|
|
17
|
+
errors[_path] = { message, type: '' + type };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (validateAllFieldCriteria) {
|
|
21
|
+
const types = errors[_path].types;
|
|
22
|
+
const messages = types && types['' + type];
|
|
23
|
+
|
|
24
|
+
errors[_path] = appendErrors(
|
|
25
|
+
_path,
|
|
26
|
+
validateAllFieldCriteria,
|
|
27
|
+
errors,
|
|
28
|
+
'' + type,
|
|
29
|
+
messages
|
|
30
|
+
? ([] as string[]).concat(messages as string[], error.message)
|
|
31
|
+
: error.message,
|
|
32
|
+
) as FieldError;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_errors.shift();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return errors;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const typeboxResolver: Resolver =
|
|
42
|
+
(schema) => async (values, _, options) => {
|
|
43
|
+
const errors = Array.from(Value.Errors(schema, values));
|
|
44
|
+
|
|
45
|
+
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
|
|
46
|
+
|
|
47
|
+
if (!errors.length) {
|
|
48
|
+
return {
|
|
49
|
+
errors: {} as FieldErrors,
|
|
50
|
+
values,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
values: {},
|
|
56
|
+
errors: toNestError(
|
|
57
|
+
parseErrorSchema(
|
|
58
|
+
errors,
|
|
59
|
+
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
|
|
60
|
+
),
|
|
61
|
+
options,
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
export type Resolver = <T extends ReturnType<typeof Type.Object>>(
|
|
5
|
+
schema: T,
|
|
6
|
+
) => <TFieldValues extends FieldValues, TContext>(
|
|
7
|
+
values: TFieldValues,
|
|
8
|
+
context: TContext | undefined,
|
|
9
|
+
options: ResolverOptions<TFieldValues>,
|
|
10
|
+
) => Promise<ResolverResult<TFieldValues>>;
|
package/vest/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './vest';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './vest';
|
|
2
|
+
export * from './types';
|
package/vest/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
-
import * as Vest from 'vest';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
mode?: 'async' | 'sync';
|
|
6
|
-
rawValues?: boolean;
|
|
7
|
-
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
8
|
-
export
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
+
import * as Vest from 'vest';
|
|
3
|
+
export type ICreateResult = ReturnType<typeof Vest.create>;
|
|
4
|
+
export type Resolver = (schema: ICreateResult, schemaOptions?: never, factoryOptions?: {
|
|
5
|
+
mode?: 'async' | 'sync';
|
|
6
|
+
rawValues?: boolean;
|
|
7
|
+
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
8
|
+
export type VestErrors = Record<string, string[]>;
|
package/vest/dist/vest.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Resolver } from './types';
|
|
2
|
-
export declare const vestResolver: Resolver;
|
|
1
|
+
import type { Resolver } from './types';
|
|
2
|
+
export declare const vestResolver: Resolver;
|
package/vest/dist/vest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","_context","options","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","mode","promisify"],"mappings":"6JAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,
|
|
1
|
+
{"version":3,"file":"vest.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","_context","options","_temp2","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","promisify","then","e","reject"],"mappings":"6JAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAA,EAC3C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,uBAGE,SAACQ,EAAQC,EAAGC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAA,GAAE,SACzBC,EAAQC,EAAUC,GAAO,IAAIC,IAAAA,EAAAA,SAC5BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAA,EACRX,OAAQiB,EAAAA,YACNpB,EACEkB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAAA,uBAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQX,OAAQ,CAAA,GAAK,EApBGsB,OAAAA,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,IAAOW,QAAAC,QACRE,EAAS,QAACjB,EAAViB,CAAkBd,IAAOe,KAAAZ,GAmBvC,CAAC,MAAAa,GAAAL,OAAAA,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{toNestError as r,validateFieldsNatively as o}from"@hookform/resolvers";import e from"vest/promisify";const s=(r,o)=>{const e={};for(const s in r)e[s]||(e[s]={message:r[s][0],type:""}),o&&(e[s].types=r[s].reduce((r,o,e)=>(r[e]=o)&&r,{}));return e},t=(t,a,i={})=>async(a,n,l)=>{const c="sync"===i.mode?t(a):await e(t)(a);return c.hasErrors()?{values:{},errors:r(s(c.getErrors(),!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:(l.shouldUseNativeValidation&&o({},l),{values:a,errors:{}})};export{t as vestResolver};
|
|
2
|
-
//# sourceMappingURL=vest.modern.
|
|
2
|
+
//# sourceMappingURL=vest.modern.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vest.modern.mjs","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","async","values","_context","options","result","mode","promisify","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively"],"mappings":"4GAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,CAAE,EAC7C,IAAK,MAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,CAACC,EAAKJ,EAASK,KAAWD,EAAIC,GAASL,IAAYI,EACnD,CAAE,IAIR,OAAON,GAGIQ,EACXA,CAACC,EAAQC,EAAGC,EAAkB,KAC9BC,MAAOC,EAAQC,EAAUC,KACvB,MAAMC,EACqB,SAAzBL,EAAgBM,KACZR,EAAOI,SACDK,EAAUT,EAAVS,CAAkBL,GAE9B,OAAIG,EAAOG,YACF,CACLN,OAAQ,CAAE,EACVb,OAAQoB,EACNvB,EACEmB,EAAOK,aACNN,EAAQO,2BACkB,QAAzBP,EAAQQ,cAEZR,KAKNA,EAAQO,2BAA6BE,EAAuB,CAAA,EAAIT,GAEzD,CAAEF,SAAQb,OAAQ,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.module.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","values","_context","options","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","mode","promisify"],"mappings":"4GAKA,IAAMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,
|
|
1
|
+
{"version":3,"file":"vest.module.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","values","_context","options","_temp2","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","promisify","then","e","reject"],"mappings":"4GAKA,IAAMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAA,EAC3C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,EAEaQ,EACX,SAACC,EAAQC,EAAGC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAA,GAAE,SACzBC,EAAQC,EAAUC,GAAO,IAAIC,IAAAA,EAAAA,SAC5BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAA,EACRZ,OAAQkB,EACNrB,EACEmB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQZ,OAAQ,CAAA,GAAK,EApBGuB,OAAAA,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,IAAOW,QAAAC,QACRE,EAAUjB,EAAViB,CAAkBd,IAAOe,KAAAZ,GAmBvC,CAAC,MAAAa,GAAAL,OAAAA,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.umd.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","_context","options","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","mode","promisify"],"mappings":"mdAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,
|
|
1
|
+
{"version":3,"file":"vest.umd.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","_context","options","_temp2","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","promisify","then","e","reject"],"mappings":"mdAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAA,EAC3C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,iBAGE,SAACQ,EAAQC,EAAGC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAA,GAAE,SACzBC,EAAQC,EAAUC,GAAO,IAAIC,IAAAA,EAAAA,SAC5BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAA,EACRX,OAAQiB,EAAAA,YACNpB,EACEkB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAAA,uBAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQX,OAAQ,CAAA,GAAK,EApBGsB,OAAAA,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,IAAOW,QAAAC,QACRE,EAAS,QAACjB,EAAViB,CAAkBd,IAAOe,KAAAZ,GAmBvC,CAAC,MAAAa,GAAAL,OAAAA,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -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 * as vest from 'vest';
|
|
@@ -45,7 +45,7 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
test("form's native validation with Vest", async () => {
|
|
48
|
-
const handleSubmit =
|
|
48
|
+
const handleSubmit = vi.fn();
|
|
49
49
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
50
50
|
|
|
51
51
|
// username
|
|
@@ -62,9 +62,7 @@ test("form's native validation with Vest", async () => {
|
|
|
62
62
|
expect(passwordField.validity.valid).toBe(true);
|
|
63
63
|
expect(passwordField.validationMessage).toBe('');
|
|
64
64
|
|
|
65
|
-
await
|
|
66
|
-
user.click(screen.getByText(/submit/i));
|
|
67
|
-
});
|
|
65
|
+
await user.click(screen.getByText(/submit/i));
|
|
68
66
|
|
|
69
67
|
// username
|
|
70
68
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -76,10 +74,8 @@ test("form's native validation with Vest", async () => {
|
|
|
76
74
|
expect(passwordField.validity.valid).toBe(false);
|
|
77
75
|
expect(passwordField.validationMessage).toBe(PASSWORD_SYMBOL_MESSAGE);
|
|
78
76
|
|
|
79
|
-
await
|
|
80
|
-
|
|
81
|
-
user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
82
|
-
});
|
|
77
|
+
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
|
78
|
+
await user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
83
79
|
|
|
84
80
|
// username
|
|
85
81
|
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 * as vest from 'vest';
|
|
@@ -47,18 +47,14 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
test("form's validation with Vest and TypeScript's integration", async () => {
|
|
50
|
-
const handleSubmit =
|
|
50
|
+
const handleSubmit = vi.fn();
|
|
51
51
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
52
52
|
|
|
53
|
-
expect(screen.queryAllByRole(
|
|
53
|
+
expect(screen.queryAllByRole('alert')).toHaveLength(0);
|
|
54
54
|
|
|
55
|
-
await
|
|
56
|
-
user.click(screen.getByText(/submit/i));
|
|
57
|
-
});
|
|
55
|
+
await user.click(screen.getByText(/submit/i));
|
|
58
56
|
|
|
59
|
-
expect(screen.getByText(/Username is required/i)).
|
|
60
|
-
expect(
|
|
61
|
-
screen.getByText(/Password must contain a symbol/i),
|
|
62
|
-
).toBeInTheDocument();
|
|
57
|
+
expect(screen.getByText(/Username is required/i)).toBeVisible();
|
|
58
|
+
expect(screen.getByText(/Password must contain a symbol/i)).toBeVisible();
|
|
63
59
|
expect(handleSubmit).not.toHaveBeenCalled();
|
|
64
60
|
});
|