11import { reactive , ref , nextTick } from 'vue'
22import { describe , it , expect , test , beforeEach , vi } from 'vitest'
3+ import type { DOMWrapper , VueWrapper } from '@vue/test-utils'
4+ import { flushPromises } from '@vue/test-utils'
5+ import { mountSuspended } from '@nuxt/test-utils/runtime'
6+ import { z } from 'zod'
7+ import * as yup from 'yup'
8+ import Joi from 'joi'
9+ import * as valibot from 'valibot'
10+ import ComponentRender from '../component-render'
311import type { FormProps } from '../../src/runtime/components/Form.vue'
412import {
513 UForm ,
@@ -15,38 +23,31 @@ import {
1523 // UToggle,
1624 // URange
1725} from '#components'
18- import { DOMWrapper , flushPromises , VueWrapper } from '@vue/test-utils'
19- import ComponentRender from '../component-render'
20-
21- import { mountSuspended } from '@nuxt/test-utils/runtime'
22- import { z } from 'zod'
23- import * as yup from 'yup'
24- import Joi from 'joi'
25- import * as valibot from 'valibot'
2626
27- async function triggerEvent (
27+ async function triggerEvent (
2828 el : DOMWrapper < Element > | VueWrapper < any , any > ,
2929 event : string
3030) {
3131 el . trigger ( event )
3232 return flushPromises ( )
3333}
3434
35- async function setValue (
35+ async function setValue (
3636 el : DOMWrapper < Element > | VueWrapper < any , any > ,
3737 value : any
3838) {
3939 el . setValue ( value )
4040 return flushPromises ( )
4141}
4242
43- async function renderForm ( options : {
43+ async function renderForm ( options : {
4444 props : Partial < FormProps < any > >
4545 slotVars ?: object
4646 slotComponents ?: any
4747 slotTemplate : string
4848} ) {
4949 const state = reactive ( { } )
50+
5051 return await mountSuspended ( UForm , {
5152 props : {
5253 id : 42 ,
@@ -55,8 +56,8 @@ async function renderForm (options: {
5556 } ,
5657 slots : {
5758 default : {
58- // @ts -ignore
59- setup ( ) {
59+ // @ts -expect-error setup does not exist on type
60+ setup ( ) {
6061 return { state, ...options . slotVars }
6162 } ,
6263 components : {
@@ -112,7 +113,7 @@ describe('Form', () => {
112113 }
113114 ] ,
114115 [ 'custom' , {
115- async validate ( state : any ) {
116+ async validate ( state : any ) {
116117 const errs = [ ]
117118 if ( ! state . email )
118119 errs . push ( { name : 'email' , message : 'Email is required' } )
@@ -152,7 +153,7 @@ describe('Form', () => {
152153
153154 await triggerEvent ( form , 'submit.prevent' )
154155
155- // @ts -ignore
156+ // @ts -expect-error object is possibly undefined
156157 expect ( wrapper . emitted ( 'error' ) [ 0 ] [ 0 ] . errors ) . toMatchObject ( [
157158 {
158159 id : 'password' ,
@@ -181,7 +182,7 @@ describe('Form', () => {
181182 const wrapper = await renderForm ( {
182183 props : {
183184 validateOn : [ 'blur' ] ,
184- async validate ( state : any ) {
185+ async validate ( state : any ) {
185186 if ( ! state . value )
186187 return [ { name : 'value' , message : 'Error message' } ]
187188 return [ ]
@@ -216,7 +217,7 @@ describe('Form', () => {
216217 const wrapper = await renderForm ( {
217218 props : {
218219 validateOn : [ 'change' ] ,
219- async validate ( state : any ) {
220+ async validate ( state : any ) {
220221 if ( ! state . value )
221222 return [ { name : 'value' , message : 'Error message' } ]
222223 return [ ]
@@ -416,7 +417,7 @@ describe('Form', () => {
416417 const wrapper = await renderForm ( {
417418 props : {
418419 validateOn : [ 'input' , 'blur' ] ,
419- async validate ( state : any ) {
420+ async validate ( state : any ) {
420421 if ( ! state . value )
421422 return [ { name : 'value' , message : 'Error message' } ]
422423 return [ ]
@@ -445,11 +446,10 @@ describe('Form', () => {
445446
446447 await setValue ( input , validInputValue )
447448 // Waiting because of the debounced validation on input event.
448- await new Promise ( ( r ) => setTimeout ( r , 50 ) )
449+ await new Promise ( r => setTimeout ( r , 50 ) )
449450 expect ( wrapper . text ( ) ) . not . toContain ( 'Error message' )
450451 } )
451452
452-
453453 describe ( 'api' , async ( ) => {
454454 let wrapper : any
455455 let form : any
@@ -462,7 +462,7 @@ describe('Form', () => {
462462 UForm,
463463 UInput
464464 } ,
465- setup ( ) {
465+ setup ( ) {
466466 const form = ref ( )
467467 const state = reactive ( { } )
468468 const schema = z . object ( {
@@ -605,7 +605,7 @@ describe('Form', () => {
605605 UForm,
606606 UInput
607607 } ,
608- setup ( ) {
608+ setup ( ) {
609609 const form = ref ( )
610610 const state = reactive ( { nested : { } } )
611611 const schema = z . object ( {
@@ -618,7 +618,6 @@ describe('Form', () => {
618618 field : z . string ( ) . min ( 1 )
619619 } )
620620
621-
622621 const onError = vi . fn ( )
623622 const onSubmit = vi . fn ( )
624623
@@ -651,7 +650,7 @@ describe('Form', () => {
651650 expect ( wrapper . setupState . onSubmit ) . not . toHaveBeenCalled ( )
652651 expect ( wrapper . setupState . onError ) . toHaveBeenCalledTimes ( 1 )
653652 const onErrorCallArgs = wrapper . setupState . onError . mock . lastCall [ 0 ]
654- expect ( onErrorCallArgs . childrens [ 0 ] . errors ) . toMatchObject ( [ { id : 'nestedInput' , name : 'field' , message : 'Required' } ] )
653+ expect ( onErrorCallArgs . childrens [ 0 ] . errors ) . toMatchObject ( [ { id : 'nestedInput' , name : 'field' , message : 'Required' } ] )
655654 expect ( onErrorCallArgs . errors ) . toMatchObject ( [
656655 { id : 'emailInput' , name : 'email' , message : 'Required' } ,
657656 { id : 'passwordInput' , name : 'password' , message : 'Required' }
0 commit comments