Skip to content

Commit c53864f

Browse files
authored
feat: migrate arktype resolver to v2 (#686)
1 parent 767184d commit c53864f

File tree

9 files changed

+4983
-3784
lines changed

9 files changed

+4983
-3784
lines changed

arktype/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@hookform/resolvers/arktype",
33
"amdName": "hookformResolversArktype",
4-
"version": "1.0.0",
4+
"version": "2.0.0",
55
"private": true,
66
"description": "React Hook Form validation resolver: arktype",
77
"main": "dist/arktype.js",

arktype/src/__tests__/Form-native-validation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ test("form's native validation with Zod", async () => {
5757
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
5858
expect(usernameField.validity.valid).toBe(false);
5959
expect(usernameField.validationMessage).toBe(
60-
'username must be more than 1 characters (was 0)',
60+
'username must be more than length 1 (was 0)',
6161
);
6262

6363
// password
6464
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
6565
expect(passwordField.validity.valid).toBe(false);
6666
expect(passwordField.validationMessage).toBe(
67-
'password must be more than 1 characters (was 0)',
67+
'password must be more than length 1 (was 0)',
6868
);
6969

7070
await user.type(screen.getByPlaceholderText(/username/i), 'joe');

arktype/src/__tests__/Form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ test("form's validation with arkType and TypeScript's integration", async () =>
4747
await user.click(screen.getByText(/submit/i));
4848

4949
expect(
50-
screen.getByText('username must be more than 1 characters (was 0)'),
50+
screen.getByText('username must be more than length 1 (was 0)'),
5151
).toBeInTheDocument();
5252
expect(
53-
screen.getByText('password must be more than 1 characters (was 0)'),
53+
screen.getByText('password must be more than length 1 (was 0)'),
5454
).toBeInTheDocument();
5555
expect(handleSubmit).not.toHaveBeenCalled();
5656
});

arktype/src/__tests__/__fixtures__/data.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import { Field, InternalFieldName } from 'react-hook-form';
2-
import { type, arrayOf, union } from 'arktype';
2+
import { type } from 'arktype';
33

44
export const schema = type({
55
username: 'string>2',
6-
password: union(['string>8', '&', '/.*[A-Za-z].*/'], ['/.*\\d.*/']),
6+
password: '/.*[A-Za-z].*/>8|/.*\\d.*/',
77
repeatPassword: 'string>1',
8-
accessToken: union('string', 'number'),
8+
accessToken: 'string|number',
99
birthYear: '1900<number<2013',
1010
email: 'email',
11-
tags: arrayOf('string'),
11+
tags: 'string[]',
1212
enabled: 'boolean',
1313
url: 'string>1',
14-
'like?': arrayOf(
15-
type({
16-
id: 'number',
17-
name: 'string>3',
18-
}),
19-
),
14+
'like?': type({
15+
id: 'number',
16+
name: 'string>3',
17+
}).array(),
2018
dateStr: 'Date',
2119
});
2220

0 commit comments

Comments
 (0)