1
- import { createVNode , defineComponent , h , renderSlot } from '@vue/runtime-dom'
1
+ import {
2
+ createVNode ,
3
+ defineComponent ,
4
+ h ,
5
+ nextTick ,
6
+ ref ,
7
+ renderSlot ,
8
+ toDisplayString ,
9
+ useModel ,
10
+ } from '@vue/runtime-dom'
2
11
import { makeInteropRender } from './_utils'
3
- import { createComponent , defineVaporComponent } from '../src'
12
+ import {
13
+ applyTextModel ,
14
+ child ,
15
+ createComponent ,
16
+ defineVaporComponent ,
17
+ renderEffect ,
18
+ setText ,
19
+ template ,
20
+ } from '../src'
4
21
5
22
const define = makeInteropRender ( )
6
23
@@ -26,6 +43,54 @@ describe('vdomInterop', () => {
26
43
} )
27
44
} )
28
45
46
+ describe ( 'v-model' , ( ) => {
47
+ test ( 'basic work' , async ( ) => {
48
+ const VaporChild = defineVaporComponent ( {
49
+ props : {
50
+ modelValue : { } ,
51
+ modelModifiers : { } ,
52
+ } ,
53
+ emits : [ 'update:modelValue' ] ,
54
+ setup ( __props ) {
55
+ const modelValue = useModel ( __props , 'modelValue' )
56
+
57
+ const n0 = template ( '<h1> </h1>' ) ( ) as any
58
+ const n1 = template ( '<input>' ) ( ) as any
59
+ const x0 = child ( n0 ) as any
60
+ applyTextModel (
61
+ n1 ,
62
+ ( ) => modelValue . value ,
63
+ _value => ( modelValue . value = _value ) ,
64
+ )
65
+ renderEffect ( ( ) => setText ( x0 , toDisplayString ( modelValue . value ) ) )
66
+ return [ n0 , n1 ]
67
+ } ,
68
+ } )
69
+
70
+ const { html, host } = define ( {
71
+ setup ( ) {
72
+ const msg = ref ( 'foo' )
73
+ return ( ) =>
74
+ h ( VaporChild as any , {
75
+ modelValue : msg . value ,
76
+ 'onUpdate:modelValue' : ( value : string ) => {
77
+ msg . value = value
78
+ } ,
79
+ } )
80
+ } ,
81
+ } ) . render ( )
82
+
83
+ expect ( html ( ) ) . toBe ( '<h1>foo</h1><input>' )
84
+
85
+ const inputEl = host . querySelector ( 'input' ) !
86
+ inputEl . value = 'bar'
87
+ inputEl . dispatchEvent ( new Event ( 'input' ) )
88
+
89
+ await nextTick ( )
90
+ expect ( html ( ) ) . toBe ( '<h1>bar</h1><input>' )
91
+ } )
92
+ } )
93
+
29
94
describe ( 'emit' , ( ) => {
30
95
test ( 'emit from vapor child to vdom parent' , ( ) => {
31
96
const VaporChild = defineVaporComponent ( {
0 commit comments