@hookform/resolvers 3.2.0 → 3.3.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.
Files changed (165) hide show
  1. package/ajv/dist/ajv.js +1 -1
  2. package/ajv/dist/ajv.js.map +1 -1
  3. package/ajv/dist/ajv.mjs +1 -1
  4. package/ajv/dist/ajv.modern.mjs +1 -1
  5. package/ajv/dist/ajv.modern.mjs.map +1 -1
  6. package/ajv/dist/ajv.module.js +1 -1
  7. package/ajv/dist/ajv.module.js.map +1 -1
  8. package/ajv/dist/ajv.umd.js +1 -1
  9. package/ajv/dist/ajv.umd.js.map +1 -1
  10. package/ajv/src/ajv.ts +2 -2
  11. package/arktype/dist/arktype.js +1 -1
  12. package/arktype/dist/arktype.js.map +1 -1
  13. package/arktype/dist/arktype.mjs +1 -1
  14. package/arktype/dist/arktype.modern.mjs +1 -1
  15. package/arktype/dist/arktype.modern.mjs.map +1 -1
  16. package/arktype/dist/arktype.module.js +1 -1
  17. package/arktype/dist/arktype.module.js.map +1 -1
  18. package/arktype/dist/arktype.umd.js +1 -1
  19. package/arktype/dist/arktype.umd.js.map +1 -1
  20. package/arktype/src/arktype.ts +2 -2
  21. package/class-validator/dist/class-validator.js +1 -1
  22. package/class-validator/dist/class-validator.js.map +1 -1
  23. package/class-validator/dist/class-validator.mjs +1 -1
  24. package/class-validator/dist/class-validator.modern.mjs +1 -1
  25. package/class-validator/dist/class-validator.modern.mjs.map +1 -1
  26. package/class-validator/dist/class-validator.module.js +1 -1
  27. package/class-validator/dist/class-validator.module.js.map +1 -1
  28. package/class-validator/dist/class-validator.umd.js +1 -1
  29. package/class-validator/dist/class-validator.umd.js.map +1 -1
  30. package/class-validator/src/__tests__/class-validator.ts +41 -0
  31. package/class-validator/src/class-validator.ts +6 -3
  32. package/computed-types/dist/computed-types.js +1 -1
  33. package/computed-types/dist/computed-types.js.map +1 -1
  34. package/computed-types/dist/computed-types.mjs +1 -1
  35. package/computed-types/dist/computed-types.modern.mjs +1 -1
  36. package/computed-types/dist/computed-types.modern.mjs.map +1 -1
  37. package/computed-types/dist/computed-types.module.js +1 -1
  38. package/computed-types/dist/computed-types.module.js.map +1 -1
  39. package/computed-types/dist/computed-types.umd.js +1 -1
  40. package/computed-types/dist/computed-types.umd.js.map +1 -1
  41. package/computed-types/src/computed-types.ts +2 -2
  42. package/dist/index.d.ts +1 -1
  43. package/dist/resolvers.js +1 -1
  44. package/dist/resolvers.js.map +1 -1
  45. package/dist/resolvers.mjs +1 -1
  46. package/dist/resolvers.mjs.map +1 -1
  47. package/dist/resolvers.module.js +1 -1
  48. package/dist/resolvers.module.js.map +1 -1
  49. package/dist/resolvers.umd.js +1 -1
  50. package/dist/resolvers.umd.js.map +1 -1
  51. package/dist/toNestErrors.d.ts +2 -0
  52. package/io-ts/dist/io-ts.js +1 -1
  53. package/io-ts/dist/io-ts.js.map +1 -1
  54. package/io-ts/dist/io-ts.mjs +1 -1
  55. package/io-ts/dist/io-ts.modern.mjs +1 -1
  56. package/io-ts/dist/io-ts.modern.mjs.map +1 -1
  57. package/io-ts/dist/io-ts.module.js +1 -1
  58. package/io-ts/dist/io-ts.module.js.map +1 -1
  59. package/io-ts/dist/io-ts.umd.js +1 -1
  60. package/io-ts/dist/io-ts.umd.js.map +1 -1
  61. package/io-ts/src/io-ts.ts +2 -2
  62. package/joi/dist/joi.js +1 -1
  63. package/joi/dist/joi.js.map +1 -1
  64. package/joi/dist/joi.mjs +1 -1
  65. package/joi/dist/joi.modern.mjs +1 -1
  66. package/joi/dist/joi.modern.mjs.map +1 -1
  67. package/joi/dist/joi.module.js +1 -1
  68. package/joi/dist/joi.module.js.map +1 -1
  69. package/joi/dist/joi.umd.js +1 -1
  70. package/joi/dist/joi.umd.js.map +1 -1
  71. package/joi/src/joi.ts +2 -2
  72. package/nope/dist/nope.js +1 -1
  73. package/nope/dist/nope.js.map +1 -1
  74. package/nope/dist/nope.mjs +1 -1
  75. package/nope/dist/nope.modern.mjs +1 -1
  76. package/nope/dist/nope.modern.mjs.map +1 -1
  77. package/nope/dist/nope.module.js +1 -1
  78. package/nope/dist/nope.module.js.map +1 -1
  79. package/nope/dist/nope.umd.js +1 -1
  80. package/nope/dist/nope.umd.js.map +1 -1
  81. package/nope/src/nope.ts +3 -3
  82. package/package.json +26 -27
  83. package/superstruct/dist/superstruct.js +1 -1
  84. package/superstruct/dist/superstruct.js.map +1 -1
  85. package/superstruct/dist/superstruct.mjs +1 -1
  86. package/superstruct/dist/superstruct.modern.mjs +1 -1
  87. package/superstruct/dist/superstruct.modern.mjs.map +1 -1
  88. package/superstruct/dist/superstruct.module.js +1 -1
  89. package/superstruct/dist/superstruct.module.js.map +1 -1
  90. package/superstruct/dist/superstruct.umd.js +1 -1
  91. package/superstruct/dist/superstruct.umd.js.map +1 -1
  92. package/superstruct/src/superstruct.ts +2 -2
  93. package/typanion/dist/typanion.js +1 -1
  94. package/typanion/dist/typanion.js.map +1 -1
  95. package/typanion/dist/typanion.mjs +1 -1
  96. package/typanion/dist/typanion.modern.mjs +1 -1
  97. package/typanion/dist/typanion.modern.mjs.map +1 -1
  98. package/typanion/dist/typanion.module.js +1 -1
  99. package/typanion/dist/typanion.module.js.map +1 -1
  100. package/typanion/dist/typanion.umd.js +1 -1
  101. package/typanion/dist/typanion.umd.js.map +1 -1
  102. package/typanion/src/typanion.ts +2 -2
  103. package/typebox/dist/typebox.js +1 -1
  104. package/typebox/dist/typebox.js.map +1 -1
  105. package/typebox/dist/typebox.mjs +1 -1
  106. package/typebox/dist/typebox.modern.mjs +1 -1
  107. package/typebox/dist/typebox.modern.mjs.map +1 -1
  108. package/typebox/dist/typebox.module.js +1 -1
  109. package/typebox/dist/typebox.module.js.map +1 -1
  110. package/typebox/dist/typebox.umd.js +1 -1
  111. package/typebox/dist/typebox.umd.js.map +1 -1
  112. package/typebox/src/__tests__/__fixtures__/data.ts +2 -7
  113. package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +57 -59
  114. package/typebox/src/typebox.ts +2 -2
  115. package/valibot/dist/valibot.js +1 -1
  116. package/valibot/dist/valibot.js.map +1 -1
  117. package/valibot/dist/valibot.mjs +1 -1
  118. package/valibot/dist/valibot.modern.mjs +1 -1
  119. package/valibot/dist/valibot.modern.mjs.map +1 -1
  120. package/valibot/dist/valibot.module.js +1 -1
  121. package/valibot/dist/valibot.module.js.map +1 -1
  122. package/valibot/dist/valibot.umd.js +1 -1
  123. package/valibot/dist/valibot.umd.js.map +1 -1
  124. package/valibot/src/__tests__/Form-native-validation.tsx +81 -0
  125. package/valibot/src/__tests__/Form.tsx +61 -0
  126. package/valibot/src/__tests__/__fixtures__/data.ts +2 -1
  127. package/valibot/src/__tests__/__snapshots__/valibot.ts.snap +339 -0
  128. package/valibot/src/__tests__/valibot.ts +77 -0
  129. package/valibot/src/valibot.ts +57 -42
  130. package/vest/dist/types.d.ts +4 -4
  131. package/vest/dist/vest.js +1 -1
  132. package/vest/dist/vest.js.map +1 -1
  133. package/vest/dist/vest.mjs +1 -1
  134. package/vest/dist/vest.modern.mjs +1 -1
  135. package/vest/dist/vest.modern.mjs.map +1 -1
  136. package/vest/dist/vest.module.js +1 -1
  137. package/vest/dist/vest.module.js.map +1 -1
  138. package/vest/dist/vest.umd.js +1 -1
  139. package/vest/dist/vest.umd.js.map +1 -1
  140. package/vest/src/__tests__/vest.ts +13 -0
  141. package/vest/src/types.ts +10 -7
  142. package/vest/src/vest.ts +5 -5
  143. package/yup/dist/yup.d.ts +2 -2
  144. package/yup/dist/yup.js +1 -1
  145. package/yup/dist/yup.js.map +1 -1
  146. package/yup/dist/yup.mjs +1 -1
  147. package/yup/dist/yup.modern.mjs +1 -1
  148. package/yup/dist/yup.modern.mjs.map +1 -1
  149. package/yup/dist/yup.module.js +1 -1
  150. package/yup/dist/yup.module.js.map +1 -1
  151. package/yup/dist/yup.umd.js +1 -1
  152. package/yup/dist/yup.umd.js.map +1 -1
  153. package/yup/src/__tests__/yup.ts +25 -31
  154. package/yup/src/yup.ts +6 -4
  155. package/zod/dist/zod.js +1 -1
  156. package/zod/dist/zod.js.map +1 -1
  157. package/zod/dist/zod.mjs +1 -1
  158. package/zod/dist/zod.modern.mjs +1 -1
  159. package/zod/dist/zod.modern.mjs.map +1 -1
  160. package/zod/dist/zod.module.js +1 -1
  161. package/zod/dist/zod.module.js.map +1 -1
  162. package/zod/dist/zod.umd.js +1 -1
  163. package/zod/dist/zod.umd.js.map +1 -1
  164. package/zod/src/zod.ts +2 -2
  165. package/dist/toNestError.d.ts +0 -2
@@ -0,0 +1,81 @@
1
+ import React from 'react';
2
+ import { useForm } from 'react-hook-form';
3
+ import { render, screen } from '@testing-library/react';
4
+ import user from '@testing-library/user-event';
5
+ import { string, required, object, minLength } from 'valibot';
6
+ import { valibotResolver } from '..';
7
+
8
+ const USERNAME_REQUIRED_MESSAGE = 'username field is required';
9
+ const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
10
+
11
+ const schema = required(
12
+ object({
13
+ username: string(USERNAME_REQUIRED_MESSAGE, [
14
+ minLength(2, USERNAME_REQUIRED_MESSAGE),
15
+ ]),
16
+ password: string(PASSWORD_REQUIRED_MESSAGE, [
17
+ minLength(2, PASSWORD_REQUIRED_MESSAGE),
18
+ ]),
19
+ }),
20
+ );
21
+
22
+ type FormData = { username: string; password: string };
23
+
24
+ interface Props {
25
+ onSubmit: (data: FormData) => void;
26
+ }
27
+
28
+ function TestComponent({ onSubmit }: Props) {
29
+ const { register, handleSubmit } = useForm<FormData>({
30
+ resolver: valibotResolver(schema),
31
+ shouldUseNativeValidation: true,
32
+ });
33
+
34
+ return (
35
+ <form onSubmit={handleSubmit(onSubmit)}>
36
+ <input {...register('username')} placeholder="username" />
37
+
38
+ <input {...register('password')} placeholder="password" />
39
+
40
+ <button type="submit">submit</button>
41
+ </form>
42
+ );
43
+ }
44
+
45
+ test("form's native validation with Zod", async () => {
46
+ const handleSubmit = vi.fn();
47
+ render(<TestComponent onSubmit={handleSubmit} />);
48
+
49
+ // username
50
+ let usernameField = screen.getByPlaceholderText(
51
+ /username/i,
52
+ ) as HTMLInputElement;
53
+ expect(usernameField.validity.valid).toBe(true);
54
+ expect(usernameField.validationMessage).toBe('');
55
+
56
+ // password
57
+ let passwordField = screen.getByPlaceholderText(
58
+ /password/i,
59
+ ) as HTMLInputElement;
60
+ expect(passwordField.validity.valid).toBe(true);
61
+ expect(passwordField.validationMessage).toBe('');
62
+
63
+ await user.click(screen.getByText(/submit/i));
64
+
65
+ // username
66
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
67
+ expect(usernameField.validity.valid).toBe(false);
68
+ expect(usernameField.validationMessage).toBe(USERNAME_REQUIRED_MESSAGE);
69
+
70
+ // password
71
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
72
+ expect(passwordField.validity.valid).toBe(false);
73
+ expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
74
+
75
+ await user.type(screen.getByPlaceholderText(/password/i), 'password');
76
+
77
+ // password
78
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
79
+ expect(passwordField.validity.valid).toBe(true);
80
+ expect(passwordField.validationMessage).toBe('');
81
+ });
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import user from '@testing-library/user-event';
4
+ import { useForm } from 'react-hook-form';
5
+ import { string, required, object, minLength } from 'valibot';
6
+ import { valibotResolver } from '..';
7
+
8
+ const USERNAME_REQUIRED_MESSAGE = 'username field is required';
9
+ const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
10
+
11
+ const schema = required(
12
+ object({
13
+ username: string(USERNAME_REQUIRED_MESSAGE, [
14
+ minLength(2, USERNAME_REQUIRED_MESSAGE),
15
+ ]),
16
+ password: string(PASSWORD_REQUIRED_MESSAGE, [
17
+ minLength(2, PASSWORD_REQUIRED_MESSAGE),
18
+ ]),
19
+ }),
20
+ );
21
+
22
+ type FormData = { username: string; password: string };
23
+
24
+ interface Props {
25
+ onSubmit: (data: FormData) => void;
26
+ }
27
+
28
+ function TestComponent({ onSubmit }: Props) {
29
+ const {
30
+ register,
31
+ handleSubmit,
32
+ formState: { errors },
33
+ } = useForm<FormData>({
34
+ resolver: valibotResolver(schema), // Useful to check TypeScript regressions
35
+ });
36
+
37
+ return (
38
+ <form onSubmit={handleSubmit(onSubmit)}>
39
+ <input {...register('username')} />
40
+ {errors.username && <span role="alert">{errors.username.message}</span>}
41
+
42
+ <input {...register('password')} />
43
+ {errors.password && <span role="alert">{errors.password.message}</span>}
44
+
45
+ <button type="submit">submit</button>
46
+ </form>
47
+ );
48
+ }
49
+
50
+ test("form's validation with Valibot and TypeScript's integration", async () => {
51
+ const handleSubmit = vi.fn();
52
+ render(<TestComponent onSubmit={handleSubmit} />);
53
+
54
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
55
+
56
+ await user.click(screen.getByText(/submit/i));
57
+
58
+ expect(screen.getByText(/username field is required/i)).toBeInTheDocument();
59
+ expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
60
+ expect(handleSubmit).not.toHaveBeenCalled();
61
+ });
@@ -12,6 +12,7 @@ import {
12
12
  array,
13
13
  boolean,
14
14
  required,
15
+ union
15
16
  } from 'valibot';
16
17
 
17
18
  export const schema = required(
@@ -28,7 +29,7 @@ export const schema = required(
28
29
  minLength(8, 'Must be at least 8 characters in length'),
29
30
  ]),
30
31
  repeatPassword: string('Repeat Password is required'),
31
- accessToken: string('Access token is required'),
32
+ accessToken: union([string('Access token should be a string'), number('Access token should be a number')], "access token is required"),
32
33
  birthYear: number('Please enter your birth year', [
33
34
  minValue(1900),
34
35
  maxValue(2013),
@@ -77,3 +77,342 @@ exports[`valibotResolver > should return a single error from valibotResolver whe
77
77
  "values": {},
78
78
  }
79
79
  `;
80
+
81
+ exports[`valibotResolver > should return a single error from valibotResolver with \`mode: sync\` when validation fails 1`] = `
82
+ {
83
+ "errors": {
84
+ "accessToken": {
85
+ "message": "Invalid type",
86
+ "ref": undefined,
87
+ "type": "non_optional",
88
+ },
89
+ "birthYear": {
90
+ "message": "Please enter your birth year",
91
+ "ref": undefined,
92
+ "type": "number",
93
+ },
94
+ "email": {
95
+ "message": "Invalid email address",
96
+ "ref": {
97
+ "name": "email",
98
+ },
99
+ "type": "email",
100
+ },
101
+ "enabled": {
102
+ "message": "Invalid type",
103
+ "ref": undefined,
104
+ "type": "non_optional",
105
+ },
106
+ "like": {
107
+ "id": {
108
+ "message": "Like id is required",
109
+ "ref": undefined,
110
+ "type": "number",
111
+ },
112
+ "name": {
113
+ "message": "Invalid type",
114
+ "ref": undefined,
115
+ "type": "non_optional",
116
+ },
117
+ },
118
+ "password": {
119
+ "message": "One uppercase character",
120
+ "ref": {
121
+ "name": "password",
122
+ },
123
+ "type": "regex",
124
+ },
125
+ "repeatPassword": {
126
+ "message": "Invalid type",
127
+ "ref": undefined,
128
+ "type": "non_optional",
129
+ },
130
+ "tags": [
131
+ {
132
+ "message": "Tags should be strings",
133
+ "ref": undefined,
134
+ "type": "string",
135
+ },
136
+ {
137
+ "message": "Tags should be strings",
138
+ "ref": undefined,
139
+ "type": "string",
140
+ },
141
+ {
142
+ "message": "Tags should be strings",
143
+ "ref": undefined,
144
+ "type": "string",
145
+ },
146
+ ],
147
+ "username": {
148
+ "message": "Invalid type",
149
+ "ref": {
150
+ "name": "username",
151
+ },
152
+ "type": "non_optional",
153
+ },
154
+ },
155
+ "values": {},
156
+ }
157
+ `;
158
+
159
+ exports[`valibotResolver > should return all the errors from valibotResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
160
+ {
161
+ "errors": {
162
+ "accessToken": {
163
+ "message": "Invalid type",
164
+ "ref": undefined,
165
+ "type": "non_optional",
166
+ "types": {
167
+ "non_optional": "Invalid type",
168
+ },
169
+ },
170
+ "birthYear": {
171
+ "message": "Please enter your birth year",
172
+ "ref": undefined,
173
+ "type": "number",
174
+ "types": {
175
+ "number": "Please enter your birth year",
176
+ },
177
+ },
178
+ "email": {
179
+ "message": "Invalid email address",
180
+ "ref": {
181
+ "name": "email",
182
+ },
183
+ "type": "email",
184
+ "types": {
185
+ "email": "Invalid email address",
186
+ },
187
+ },
188
+ "enabled": {
189
+ "message": "Invalid type",
190
+ "ref": undefined,
191
+ "type": "non_optional",
192
+ "types": {
193
+ "non_optional": "Invalid type",
194
+ },
195
+ },
196
+ "like": {
197
+ "id": {
198
+ "message": "Like id is required",
199
+ "ref": undefined,
200
+ "type": "number",
201
+ "types": {
202
+ "number": "Like id is required",
203
+ },
204
+ },
205
+ "name": {
206
+ "message": "Invalid type",
207
+ "ref": undefined,
208
+ "type": "non_optional",
209
+ "types": {
210
+ "non_optional": "Invalid type",
211
+ },
212
+ },
213
+ },
214
+ "password": {
215
+ "message": "One uppercase character",
216
+ "ref": {
217
+ "name": "password",
218
+ },
219
+ "type": "regex",
220
+ "types": {
221
+ "min_length": "Must be at least 8 characters in length",
222
+ "regex": [
223
+ "One uppercase character",
224
+ "One lowercase character",
225
+ "One number",
226
+ ],
227
+ },
228
+ },
229
+ "repeatPassword": {
230
+ "message": "Invalid type",
231
+ "ref": undefined,
232
+ "type": "non_optional",
233
+ "types": {
234
+ "non_optional": "Invalid type",
235
+ },
236
+ },
237
+ "tags": [
238
+ {
239
+ "message": "Tags should be strings",
240
+ "ref": undefined,
241
+ "type": "string",
242
+ "types": {
243
+ "string": "Tags should be strings",
244
+ },
245
+ },
246
+ {
247
+ "message": "Tags should be strings",
248
+ "ref": undefined,
249
+ "type": "string",
250
+ "types": {
251
+ "string": "Tags should be strings",
252
+ },
253
+ },
254
+ {
255
+ "message": "Tags should be strings",
256
+ "ref": undefined,
257
+ "type": "string",
258
+ "types": {
259
+ "string": "Tags should be strings",
260
+ },
261
+ },
262
+ ],
263
+ "username": {
264
+ "message": "Invalid type",
265
+ "ref": {
266
+ "name": "username",
267
+ },
268
+ "type": "non_optional",
269
+ "types": {
270
+ "non_optional": "Invalid type",
271
+ },
272
+ },
273
+ },
274
+ "values": {},
275
+ }
276
+ `;
277
+
278
+ exports[`valibotResolver > should return all the errors from valibotResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
279
+ {
280
+ "errors": {
281
+ "accessToken": {
282
+ "message": "Invalid type",
283
+ "ref": undefined,
284
+ "type": "non_optional",
285
+ "types": {
286
+ "non_optional": "Invalid type",
287
+ },
288
+ },
289
+ "birthYear": {
290
+ "message": "Please enter your birth year",
291
+ "ref": undefined,
292
+ "type": "number",
293
+ "types": {
294
+ "number": "Please enter your birth year",
295
+ },
296
+ },
297
+ "email": {
298
+ "message": "Invalid email address",
299
+ "ref": {
300
+ "name": "email",
301
+ },
302
+ "type": "email",
303
+ "types": {
304
+ "email": "Invalid email address",
305
+ },
306
+ },
307
+ "enabled": {
308
+ "message": "Invalid type",
309
+ "ref": undefined,
310
+ "type": "non_optional",
311
+ "types": {
312
+ "non_optional": "Invalid type",
313
+ },
314
+ },
315
+ "like": {
316
+ "id": {
317
+ "message": "Like id is required",
318
+ "ref": undefined,
319
+ "type": "number",
320
+ "types": {
321
+ "number": "Like id is required",
322
+ },
323
+ },
324
+ "name": {
325
+ "message": "Invalid type",
326
+ "ref": undefined,
327
+ "type": "non_optional",
328
+ "types": {
329
+ "non_optional": "Invalid type",
330
+ },
331
+ },
332
+ },
333
+ "password": {
334
+ "message": "One uppercase character",
335
+ "ref": {
336
+ "name": "password",
337
+ },
338
+ "type": "regex",
339
+ "types": {
340
+ "min_length": "Must be at least 8 characters in length",
341
+ "regex": [
342
+ "One uppercase character",
343
+ "One lowercase character",
344
+ "One number",
345
+ ],
346
+ },
347
+ },
348
+ "repeatPassword": {
349
+ "message": "Invalid type",
350
+ "ref": undefined,
351
+ "type": "non_optional",
352
+ "types": {
353
+ "non_optional": "Invalid type",
354
+ },
355
+ },
356
+ "tags": [
357
+ {
358
+ "message": "Tags should be strings",
359
+ "ref": undefined,
360
+ "type": "string",
361
+ "types": {
362
+ "string": "Tags should be strings",
363
+ },
364
+ },
365
+ {
366
+ "message": "Tags should be strings",
367
+ "ref": undefined,
368
+ "type": "string",
369
+ "types": {
370
+ "string": "Tags should be strings",
371
+ },
372
+ },
373
+ {
374
+ "message": "Tags should be strings",
375
+ "ref": undefined,
376
+ "type": "string",
377
+ "types": {
378
+ "string": "Tags should be strings",
379
+ },
380
+ },
381
+ ],
382
+ "username": {
383
+ "message": "Invalid type",
384
+ "ref": {
385
+ "name": "username",
386
+ },
387
+ "type": "non_optional",
388
+ "types": {
389
+ "non_optional": "Invalid type",
390
+ },
391
+ },
392
+ },
393
+ "values": {},
394
+ }
395
+ `;
396
+
397
+ exports[`valibotResolver > should return parsed values from valibotResolver with \`mode: sync\` when validation pass 1`] = `
398
+ {
399
+ "errors": {},
400
+ "values": {
401
+ "accessToken": "accessToken",
402
+ "birthYear": 2000,
403
+ "email": "john@doe.com",
404
+ "enabled": true,
405
+ "like": {
406
+ "id": 1,
407
+ "name": "name",
408
+ },
409
+ "password": "Password123_",
410
+ "repeatPassword": "Password123_",
411
+ "tags": [
412
+ "tag1",
413
+ "tag2",
414
+ ],
415
+ "username": "Doe",
416
+ },
417
+ }
418
+ `;
@@ -1,9 +1,51 @@
1
1
  /* eslint-disable no-console, @typescript-eslint/ban-ts-comment */
2
2
  import { valibotResolver } from '..';
3
3
  import { schema, validData, fields, invalidData } from './__fixtures__/data';
4
+ import * as valibot from 'valibot';
4
5
 
5
6
  const shouldUseNativeValidation = false;
6
7
  describe('valibotResolver', () => {
8
+ it('should return parsed values from valibotResolver with `mode: sync` when validation pass', async () => {
9
+ vi.mock('valibot', async () => {
10
+ const a = await vi.importActual<any>('valibot');
11
+ return {
12
+ __esModule: true,
13
+ ...a,
14
+ };
15
+ });
16
+ const parseSpy = vi.spyOn(valibot, 'parse');
17
+ const parseAsyncSpy = vi.spyOn(valibot, 'parseAsync');
18
+
19
+ const result = await valibotResolver(schema, undefined, {
20
+ mode: 'sync',
21
+ })(validData, undefined, { fields, shouldUseNativeValidation });
22
+
23
+ expect(parseSpy).toHaveBeenCalledTimes(1);
24
+ expect(parseAsyncSpy).not.toHaveBeenCalled();
25
+ expect(result.errors).toEqual({});
26
+ expect(result).toMatchSnapshot();
27
+ });
28
+
29
+ it('should return a single error from valibotResolver with `mode: sync` when validation fails', async () => {
30
+ vi.mock('valibot', async () => {
31
+ const a = await vi.importActual<any>('valibot');
32
+ return {
33
+ __esModule: true,
34
+ ...a,
35
+ };
36
+ });
37
+ const parseSpy = vi.spyOn(valibot, 'parse');
38
+ const parseAsyncSpy = vi.spyOn(valibot, 'parseAsync');
39
+
40
+ const result = await valibotResolver(schema, undefined, {
41
+ mode: 'sync',
42
+ })(invalidData, undefined, { fields, shouldUseNativeValidation });
43
+
44
+ expect(parseSpy).toHaveBeenCalledTimes(1);
45
+ expect(parseAsyncSpy).not.toHaveBeenCalled();
46
+ expect(result).toMatchSnapshot();
47
+ });
48
+
7
49
  it('should return values from valibotResolver when validation pass', async () => {
8
50
  const result = await valibotResolver(schema)(validData, undefined, {
9
51
  fields,
@@ -21,4 +63,39 @@ describe('valibotResolver', () => {
21
63
 
22
64
  expect(result).toMatchSnapshot();
23
65
  });
66
+
67
+ it('should return values from valibotResolver when validation pass & raw=true', async () => {
68
+ const result = await valibotResolver(schema, undefined, {
69
+ raw: true,
70
+ })(validData, undefined, {
71
+ fields,
72
+ shouldUseNativeValidation,
73
+ });
74
+
75
+ expect(result).toEqual({ errors: {}, values: validData });
76
+ });
77
+
78
+ it('should return all the errors from valibotResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
79
+ const result = await valibotResolver(schema)(invalidData, undefined, {
80
+ fields,
81
+ criteriaMode: 'all',
82
+ shouldUseNativeValidation,
83
+ });
84
+
85
+ expect(result).toMatchSnapshot();
86
+ });
87
+
88
+ it('should return all the errors from valibotResolver when validation fails with `validateAllFieldCriteria` set to true and `mode: sync`', async () => {
89
+ const result = await valibotResolver(schema, undefined, { mode: 'sync' })(
90
+ invalidData,
91
+ undefined,
92
+ {
93
+ fields,
94
+ criteriaMode: 'all',
95
+ shouldUseNativeValidation,
96
+ },
97
+ );
98
+
99
+ expect(result).toMatchSnapshot();
100
+ });
24
101
  });