@@ -614,32 +614,31 @@ describe('useModel', () => {
614
614
} )
615
615
616
616
test ( 'set no change value' , async ( ) => {
617
- let changeChildMsg : ( ( ) => void ) | null = null
617
+ let changeChildMsg ! : ( val : string ) => void
618
618
619
- const compRender = vi . fn ( )
619
+ const setValue = vi . fn ( )
620
620
const Comp = defineComponent ( {
621
621
props : [ 'msg' ] ,
622
622
emits : [ 'update:msg' ] ,
623
623
setup ( props ) {
624
624
const childMsg = useModel ( props , 'msg' )
625
- changeChildMsg = ( ) => {
626
- childMsg . value = childMsg . value
627
- }
625
+ changeChildMsg = ( val : string ) => ( childMsg . value = val )
628
626
return ( ) => {
629
627
return childMsg . value
630
628
}
631
629
} ,
632
630
} )
633
631
634
- const msg = ref ( 'HI' )
632
+ const defaultVal = 'defaultVal'
633
+ const msg = ref ( defaultVal )
635
634
const Parent = defineComponent ( {
636
635
setup ( ) {
637
636
return ( ) =>
638
637
h ( Comp , {
639
638
msg : msg . value ,
640
639
'onUpdate:msg' : val => {
641
640
msg . value = val
642
- compRender ( )
641
+ setValue ( )
643
642
} ,
644
643
} )
645
644
} ,
@@ -648,8 +647,14 @@ describe('useModel', () => {
648
647
const root = nodeOps . createElement ( 'div' )
649
648
render ( h ( Parent ) , root )
650
649
651
- expect ( compRender ) . toBeCalledTimes ( 0 )
652
- changeChildMsg ! ( )
653
- expect ( compRender ) . toBeCalledTimes ( 0 )
650
+ expect ( setValue ) . toBeCalledTimes ( 0 )
651
+
652
+ changeChildMsg ( defaultVal )
653
+ expect ( setValue ) . toBeCalledTimes ( 0 )
654
+
655
+ changeChildMsg ( 'changed' )
656
+ changeChildMsg ( defaultVal )
657
+ expect ( setValue ) . toBeCalledTimes ( 2 )
658
+ expect ( msg . value ) . toBe ( defaultVal )
654
659
} )
655
660
} )
0 commit comments