Skip to content

Commit

Permalink
test: fix async validation tests with adapters (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
Balastrong authored Jul 2, 2024
1 parent dc2ece3 commit 0b38c3e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
11 changes: 8 additions & 3 deletions packages/valibot-form-adapter/tests/FieldApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ describe('valibot field api', () => {
validators: {
onChangeAsync: v.pipeAsync(
v.string(),
v.checkAsync(async (val) => val.length > 3, 'Testing 123'),
v.checkAsync(async (val) => {
await sleep(1)
return val.length > 3
}, 'Testing 123'),
),
onChangeAsyncDebounceMs: 0,
},
Expand Down Expand Up @@ -103,8 +106,10 @@ describe('valibot field api', () => {
validatorAdapter: valibotValidator(),
name: 'name',
validators: {
onChangeAsync: async ({ value }) =>
value === 'a' ? 'Test' : undefined,
onChangeAsync: async ({ value }) => {
await sleep(1)
return value === 'a' ? 'Test' : undefined
},
onChangeAsyncDebounceMs: 0,
},
})
Expand Down
13 changes: 8 additions & 5 deletions packages/yup-form-adapter/tests/FieldApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ describe('yup field api', () => {
validators: {
onChangeAsync: yup
.string()
.test('Testing 123', 'Testing 123', async (val) =>
typeof val === 'string' ? val.length > 3 : false,
),
.test('Testing 123', 'Testing 123', async (val) => {
await sleep(1)
return typeof val === 'string' ? val.length > 3 : false
}),
onChangeAsyncDebounceMs: 0,
},
})
Expand Down Expand Up @@ -101,8 +102,10 @@ describe('yup field api', () => {
validatorAdapter: yupValidator(),
name: 'name',
validators: {
onChangeAsync: async ({ value }) =>
value === 'a' ? 'Test' : undefined,
onChangeAsync: async ({ value }) => {
await sleep(1)
return value === 'a' ? 'Test' : undefined
},
onChangeAsyncDebounceMs: 0,
},
})
Expand Down
18 changes: 13 additions & 5 deletions packages/zod-form-adapter/tests/FieldApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ describe('zod field api', () => {
validatorAdapter: zodValidator(),
name: 'name',
validators: {
onChangeAsync: z.string().refine(async (val) => val.length > 3, {
message: 'Testing 123',
}),
onChangeAsync: z.string().refine(
async (val) => {
await sleep(1)
return val.length > 3
},
{
message: 'Testing 123',
},
),
onChangeAsyncDebounceMs: 0,
},
})
Expand Down Expand Up @@ -100,8 +106,10 @@ describe('zod field api', () => {
validatorAdapter: zodValidator(),
name: 'name',
validators: {
onChangeAsync: async ({ value }) =>
value === 'a' ? 'Test' : undefined,
onChangeAsync: async ({ value }) => {
await sleep(1)
return value === 'a' ? 'Test' : undefined
},
onChangeAsyncDebounceMs: 0,
},
})
Expand Down

2 comments on commit 0b38c3e

@crutchcorn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Balastrong this commit is still failing ci :( IDK why it's not lining up with our pr workflow

CC @lachlancollins

@Balastrong
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I mentioned that on discord, running the same command that ci does (test:ci) on local passes on that test and actually fails on another unrelated one for some reason.

Please sign in to comment.