@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.
Files changed (226) hide show
  1. package/README.md +51 -5
  2. package/ajv/dist/ajv.d.ts +2 -2
  3. package/ajv/dist/ajv.js +1 -7
  4. package/ajv/dist/ajv.js.map +1 -1
  5. package/ajv/dist/ajv.mjs +1 -7
  6. package/ajv/dist/ajv.modern.mjs +2 -0
  7. package/ajv/dist/ajv.modern.mjs.map +1 -0
  8. package/ajv/dist/ajv.module.js +1 -7
  9. package/ajv/dist/ajv.module.js.map +1 -1
  10. package/ajv/dist/ajv.umd.js +1 -7
  11. package/ajv/dist/ajv.umd.js.map +1 -1
  12. package/ajv/dist/index.d.ts +2 -2
  13. package/ajv/dist/types.d.ts +5 -5
  14. package/ajv/package.json +3 -1
  15. package/ajv/src/__tests__/Form-native-validation.tsx +5 -9
  16. package/ajv/src/__tests__/Form.tsx +4 -6
  17. package/ajv/src/__tests__/__fixtures__/data.ts +3 -4
  18. package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +83 -83
  19. package/ajv/src/ajv.ts +28 -24
  20. package/class-validator/dist/class-validator.d.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 +2 -0
  25. package/class-validator/dist/class-validator.modern.mjs.map +1 -0
  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/dist/index.d.ts +2 -2
  31. package/class-validator/dist/types.d.ts +12 -9
  32. package/class-validator/src/__tests__/Form-native-validation.tsx +5 -9
  33. package/class-validator/src/__tests__/Form.tsx +4 -6
  34. package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +102 -67
  35. package/class-validator/src/__tests__/class-validator.ts +66 -6
  36. package/class-validator/src/class-validator.ts +6 -4
  37. package/class-validator/src/types.ts +7 -8
  38. package/computed-types/dist/computed-types.d.ts +2 -2
  39. package/computed-types/dist/computed-types.js +1 -1
  40. package/computed-types/dist/computed-types.js.map +1 -1
  41. package/computed-types/dist/computed-types.mjs +1 -1
  42. package/computed-types/dist/computed-types.modern.mjs +2 -0
  43. package/computed-types/dist/computed-types.modern.mjs.map +1 -0
  44. package/computed-types/dist/computed-types.module.js +1 -1
  45. package/computed-types/dist/computed-types.module.js.map +1 -1
  46. package/computed-types/dist/computed-types.umd.js +1 -1
  47. package/computed-types/dist/computed-types.umd.js.map +1 -1
  48. package/computed-types/dist/index.d.ts +2 -2
  49. package/computed-types/dist/types.d.ts +2 -2
  50. package/computed-types/src/__tests__/Form-native-validation.tsx +5 -9
  51. package/computed-types/src/__tests__/Form.tsx +4 -6
  52. package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +21 -21
  53. package/computed-types/src/__tests__/computed-types.ts +16 -0
  54. package/computed-types/src/computed-types.ts +12 -5
  55. package/dist/index.d.ts +2 -2
  56. package/dist/resolvers.js +1 -1
  57. package/dist/resolvers.js.map +1 -1
  58. package/dist/resolvers.mjs +1 -1
  59. package/dist/resolvers.mjs.map +1 -1
  60. package/dist/resolvers.module.js +1 -1
  61. package/dist/resolvers.module.js.map +1 -1
  62. package/dist/resolvers.umd.js +1 -1
  63. package/dist/resolvers.umd.js.map +1 -1
  64. package/dist/toNestError.d.ts +2 -2
  65. package/dist/validateFieldsNatively.d.ts +2 -2
  66. package/io-ts/dist/arrayToPath.d.ts +3 -3
  67. package/io-ts/dist/errorsToRecord.d.ts +5 -5
  68. package/io-ts/dist/index.d.ts +2 -2
  69. package/io-ts/dist/io-ts.d.ts +2 -2
  70. package/io-ts/dist/io-ts.js +1 -1
  71. package/io-ts/dist/io-ts.js.map +1 -1
  72. package/io-ts/dist/io-ts.mjs +1 -1
  73. package/io-ts/dist/io-ts.modern.mjs +2 -0
  74. package/io-ts/dist/io-ts.modern.mjs.map +1 -0
  75. package/io-ts/dist/io-ts.module.js +1 -1
  76. package/io-ts/dist/io-ts.module.js.map +1 -1
  77. package/io-ts/dist/io-ts.umd.js +1 -1
  78. package/io-ts/dist/io-ts.umd.js.map +1 -1
  79. package/io-ts/dist/types.d.ts +7 -7
  80. package/io-ts/src/__tests__/Form-native-validation.tsx +5 -9
  81. package/io-ts/src/__tests__/Form.tsx +4 -6
  82. package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +28 -28
  83. package/io-ts/src/__tests__/io-ts.ts +1 -1
  84. package/joi/dist/index.d.ts +2 -2
  85. package/joi/dist/joi.d.ts +2 -2
  86. package/joi/dist/joi.js.map +1 -1
  87. package/joi/dist/{joi.modern.js → joi.modern.mjs} +1 -1
  88. package/joi/dist/joi.modern.mjs.map +1 -0
  89. package/joi/dist/joi.module.js.map +1 -1
  90. package/joi/dist/joi.umd.js.map +1 -1
  91. package/joi/dist/types.d.ts +5 -5
  92. package/joi/src/__tests__/Form-native-validation.tsx +5 -9
  93. package/joi/src/__tests__/Form.tsx +4 -6
  94. package/joi/src/__tests__/__snapshots__/joi.ts.snap +87 -87
  95. package/joi/src/__tests__/joi.ts +8 -8
  96. package/nope/dist/index.d.ts +2 -2
  97. package/nope/dist/nope.d.ts +2 -2
  98. package/nope/dist/nope.js.map +1 -1
  99. package/nope/dist/{nope.modern.js → nope.modern.mjs} +1 -1
  100. package/nope/dist/nope.modern.mjs.map +1 -0
  101. package/nope/dist/nope.module.js.map +1 -1
  102. package/nope/dist/nope.umd.js.map +1 -1
  103. package/nope/dist/types.d.ts +9 -9
  104. package/nope/src/__tests__/Form-native-validation.tsx +5 -9
  105. package/nope/src/__tests__/Form.tsx +4 -6
  106. package/nope/src/__tests__/__snapshots__/nope.ts.snap +15 -15
  107. package/nope/src/__tests__/nope.ts +1 -1
  108. package/package.json +74 -44
  109. package/superstruct/dist/index.d.ts +2 -2
  110. package/superstruct/dist/superstruct.d.ts +2 -2
  111. package/superstruct/dist/superstruct.js +1 -1
  112. package/superstruct/dist/superstruct.js.map +1 -1
  113. package/superstruct/dist/superstruct.mjs +1 -1
  114. package/superstruct/dist/superstruct.modern.mjs +2 -0
  115. package/superstruct/dist/superstruct.modern.mjs.map +1 -0
  116. package/superstruct/dist/superstruct.module.js +1 -1
  117. package/superstruct/dist/superstruct.module.js.map +1 -1
  118. package/superstruct/dist/superstruct.umd.js +1 -1
  119. package/superstruct/dist/superstruct.umd.js.map +1 -1
  120. package/superstruct/dist/types.d.ts +11 -5
  121. package/superstruct/src/__tests__/Form-native-validation.tsx +5 -9
  122. package/superstruct/src/__tests__/Form.tsx +4 -6
  123. package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +19 -19
  124. package/superstruct/src/__tests__/superstruct.ts +13 -0
  125. package/superstruct/src/superstruct.ts +4 -3
  126. package/superstruct/src/types.ts +8 -5
  127. package/typanion/dist/index.d.ts +2 -2
  128. package/typanion/dist/typanion.d.ts +2 -2
  129. package/typanion/dist/typanion.js.map +1 -1
  130. package/typanion/dist/{typanion.modern.js → typanion.modern.mjs} +1 -1
  131. package/typanion/dist/typanion.modern.mjs.map +1 -0
  132. package/typanion/dist/typanion.module.js.map +1 -1
  133. package/typanion/dist/typanion.umd.js.map +1 -1
  134. package/typanion/dist/types.d.ts +9 -9
  135. package/typanion/src/__tests__/Form-native-validation.tsx +7 -10
  136. package/typanion/src/__tests__/Form.tsx +9 -7
  137. package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +22 -22
  138. package/typanion/src/__tests__/typanion.ts +11 -7
  139. package/typanion/src/typanion.ts +1 -1
  140. package/typebox/dist/index.d.ts +2 -0
  141. package/typebox/dist/typebox.d.ts +2 -0
  142. package/typebox/dist/typebox.js +2 -0
  143. package/typebox/dist/typebox.js.map +1 -0
  144. package/typebox/dist/typebox.mjs +2 -0
  145. package/typebox/dist/typebox.modern.mjs +2 -0
  146. package/typebox/dist/typebox.modern.mjs.map +1 -0
  147. package/typebox/dist/typebox.module.js +2 -0
  148. package/typebox/dist/typebox.module.js.map +1 -0
  149. package/typebox/dist/typebox.umd.js +2 -0
  150. package/typebox/dist/typebox.umd.js.map +1 -0
  151. package/typebox/dist/types.d.ts +3 -0
  152. package/typebox/package.json +18 -0
  153. package/typebox/src/__tests__/Form-native-validation.tsx +83 -0
  154. package/typebox/src/__tests__/Form.tsx +54 -0
  155. package/typebox/src/__tests__/__fixtures__/data.ts +84 -0
  156. package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +190 -0
  157. package/typebox/src/__tests__/typebox.ts +34 -0
  158. package/typebox/src/index.ts +2 -0
  159. package/typebox/src/typebox.ts +64 -0
  160. package/typebox/src/types.ts +10 -0
  161. package/vest/dist/index.d.ts +2 -2
  162. package/vest/dist/types.d.ts +8 -8
  163. package/vest/dist/vest.d.ts +2 -2
  164. package/vest/dist/vest.js.map +1 -1
  165. package/vest/dist/{vest.modern.js → vest.modern.mjs} +1 -1
  166. package/vest/dist/vest.modern.mjs.map +1 -0
  167. package/vest/dist/vest.module.js.map +1 -1
  168. package/vest/dist/vest.umd.js.map +1 -1
  169. package/vest/src/__tests__/Form-native-validation.tsx +5 -9
  170. package/vest/src/__tests__/Form.tsx +6 -10
  171. package/vest/src/__tests__/__snapshots__/vest.ts.snap +47 -47
  172. package/yup/dist/index.d.ts +2 -2
  173. package/yup/dist/types.d.ts +15 -9
  174. package/yup/dist/yup.d.ts +2 -2
  175. package/yup/dist/yup.js +1 -1
  176. package/yup/dist/yup.js.map +1 -1
  177. package/yup/dist/yup.mjs +1 -1
  178. package/yup/dist/yup.modern.mjs +2 -0
  179. package/yup/dist/yup.modern.mjs.map +1 -0
  180. package/yup/dist/yup.module.js +1 -1
  181. package/yup/dist/yup.module.js.map +1 -1
  182. package/yup/dist/yup.umd.js +1 -1
  183. package/yup/dist/yup.umd.js.map +1 -1
  184. package/yup/src/__tests__/Form-native-validation.tsx +5 -9
  185. package/yup/src/__tests__/Form.tsx +4 -6
  186. package/yup/src/__tests__/__fixtures__/data.ts +2 -3
  187. package/yup/src/__tests__/__snapshots__/yup.ts.snap +100 -87
  188. package/yup/src/__tests__/yup.ts +49 -18
  189. package/yup/src/types.ts +14 -11
  190. package/yup/src/yup.ts +1 -1
  191. package/zod/dist/index.d.ts +2 -2
  192. package/zod/dist/types.d.ts +13 -13
  193. package/zod/dist/zod.d.ts +2 -2
  194. package/zod/dist/zod.js +1 -1
  195. package/zod/dist/zod.js.map +1 -1
  196. package/zod/dist/zod.mjs +1 -1
  197. package/zod/dist/zod.modern.mjs +2 -0
  198. package/zod/dist/zod.modern.mjs.map +1 -0
  199. package/zod/dist/zod.module.js +1 -1
  200. package/zod/dist/zod.module.js.map +1 -1
  201. package/zod/dist/zod.umd.js +1 -1
  202. package/zod/dist/zod.umd.js.map +1 -1
  203. package/zod/src/__tests__/Form-native-validation.tsx +5 -9
  204. package/zod/src/__tests__/Form.tsx +4 -6
  205. package/zod/src/__tests__/__snapshots__/zod.ts.snap +120 -120
  206. package/zod/src/__tests__/zod.ts +19 -7
  207. package/zod/src/types.ts +2 -6
  208. package/zod/src/zod.ts +27 -27
  209. package/ajv/dist/ajv.modern.js +0 -8
  210. package/ajv/dist/ajv.modern.js.map +0 -1
  211. package/class-validator/dist/class-validator.modern.js +0 -2
  212. package/class-validator/dist/class-validator.modern.js.map +0 -1
  213. package/computed-types/dist/computed-types.modern.js +0 -2
  214. package/computed-types/dist/computed-types.modern.js.map +0 -1
  215. package/io-ts/dist/io-ts.modern.js +0 -2
  216. package/io-ts/dist/io-ts.modern.js.map +0 -1
  217. package/joi/dist/joi.modern.js.map +0 -1
  218. package/nope/dist/nope.modern.js.map +0 -1
  219. package/superstruct/dist/superstruct.modern.js +0 -2
  220. package/superstruct/dist/superstruct.modern.js.map +0 -1
  221. package/typanion/dist/typanion.modern.js.map +0 -1
  222. package/vest/dist/vest.modern.js.map +0 -1
  223. package/yup/dist/yup.modern.js +0 -2
  224. package/yup/dist/yup.modern.js.map +0 -1
  225. package/zod/dist/zod.modern.js +0 -2
  226. 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,2 @@
1
+ export * from './typebox';
2
+ export * from './types';
@@ -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>>;
@@ -1,2 +1,2 @@
1
- export * from './vest';
2
- export * from './types';
1
+ export * from './vest';
2
+ export * from './types';
@@ -1,8 +1,8 @@
1
- import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
2
- import * as Vest from 'vest';
3
- export declare type ICreateResult = ReturnType<typeof Vest.create>;
4
- export declare 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 declare type VestErrors = Record<string, string[]>;
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[]>;
@@ -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;
@@ -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,GAC3C,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,UAAWD,EAAIC,GAASL,IAAYI,GACnD,KAIN,OAAON,wBAIP,SAACQ,EAAQC,EAAGC,mBAAAA,IAAAA,EAAkB,aACvBC,EAAQC,EAAUC,sBACjBC,GAKN,OAAIA,EAAOC,YACF,CACLJ,OAAQ,GACRX,OAAQgB,cACNnB,EACEiB,EAAOG,aACNJ,EAAQK,2BACkB,QAAzBL,EAAQM,cAEZN,KAKNA,EAAQK,2BAA6BE,yBAAuB,GAAIP,GAEzD,CAAEF,OAAAA,EAAQX,OAAQ,6BApBE,SAAzBU,EAAgBW,OACZb,EAAOG,oBACDW,UAAUd,EAAVc,CAAkBX,aALhC"}
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.js.map
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,GAC3C,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,UAAWD,EAAIC,GAASL,IAAYI,GACnD,KAIN,OAAON,GAGIQ,EACX,SAACC,EAAQC,EAAGC,mBAAAA,IAAAA,EAAkB,aACvBC,EAAQC,EAAUC,sBACjBC,GAKN,OAAIA,EAAOC,YACF,CACLJ,OAAQ,GACRZ,OAAQiB,EACNpB,EACEkB,EAAOG,aACNJ,EAAQK,2BACkB,QAAzBL,EAAQM,cAEZN,KAKNA,EAAQK,2BAA6BE,EAAuB,GAAIP,GAEzD,CAAEF,OAAAA,EAAQZ,OAAQ,6BApBE,SAAzBW,EAAgBW,OACZb,EAAOG,oBACDW,EAAUd,EAAVc,CAAkBX,aALhC"}
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,GAC3C,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,UAAWD,EAAIC,GAASL,IAAYI,GACnD,KAIN,OAAON,kBAIP,SAACQ,EAAQC,EAAGC,mBAAAA,IAAAA,EAAkB,aACvBC,EAAQC,EAAUC,sBACjBC,GAKN,OAAIA,EAAOC,YACF,CACLJ,OAAQ,GACRX,OAAQgB,cACNnB,EACEiB,EAAOG,aACNJ,EAAQK,2BACkB,QAAzBL,EAAQM,cAEZN,KAKNA,EAAQK,2BAA6BE,yBAAuB,GAAIP,GAEzD,CAAEF,OAAAA,EAAQX,OAAQ,6BApBE,SAAzBU,EAAgBW,OACZb,EAAOG,oBACDW,UAAUd,EAAVc,CAAkBX,aALhC"}
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, act } from '@testing-library/react';
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 = jest.fn();
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 act(async () => {
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 act(async () => {
80
- user.type(screen.getByPlaceholderText(/username/i), 'joe');
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, act } from '@testing-library/react';
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 = jest.fn();
50
+ const handleSubmit = vi.fn();
51
51
  render(<TestComponent onSubmit={handleSubmit} />);
52
52
 
53
- expect(screen.queryAllByRole(/alert/i)).toHaveLength(0);
53
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
54
54
 
55
- await act(async () => {
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)).toBeInTheDocument();
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
  });