1
+ var _ = require ( '../../../../src/util' )
2
+ var Vue = require ( '../../../../src/vue' )
3
+
4
+ function trigger ( target , event , process ) {
5
+ var e = document . createEvent ( 'HTMLEvents' )
6
+ e . initEvent ( event , true , true )
7
+ if ( process ) process ( e )
8
+ target . dispatchEvent ( e )
9
+ }
10
+
11
+ if ( _ . inBrowser ) {
12
+ describe ( 'v-model' , function ( ) {
13
+
14
+ var el
15
+ beforeEach ( function ( ) {
16
+ el = document . createElement ( 'div' )
17
+ document . body . appendChild ( el )
18
+ spyOn ( _ , 'warn' )
19
+ } )
20
+
21
+ afterEach ( function ( ) {
22
+ document . body . removeChild ( el )
23
+ } )
24
+
25
+ it ( 'radio buttons' , function ( done ) {
26
+ var vm = new Vue ( {
27
+ el : el ,
28
+ data : {
29
+ test : 'a'
30
+ } ,
31
+ template :
32
+ '<input type="radio" value="a" v-model="test" name="test">' +
33
+ '<input type="radio" value="b" v-model="test" name="test">'
34
+ } )
35
+ expect ( el . childNodes [ 0 ] . checked ) . toBe ( true )
36
+ expect ( el . childNodes [ 1 ] . checked ) . toBe ( false )
37
+ vm . test = 'b'
38
+ _ . nextTick ( function ( ) {
39
+ expect ( el . childNodes [ 0 ] . checked ) . toBe ( false )
40
+ expect ( el . childNodes [ 1 ] . checked ) . toBe ( true )
41
+ el . childNodes [ 0 ] . click ( )
42
+ expect ( el . childNodes [ 0 ] . checked ) . toBe ( true )
43
+ expect ( el . childNodes [ 1 ] . checked ) . toBe ( false )
44
+ expect ( vm . test ) . toBe ( 'a' )
45
+ vm . _directives [ 1 ] . unbind ( )
46
+ el . childNodes [ 1 ] . click ( )
47
+ expect ( vm . test ) . toBe ( 'a' )
48
+ done ( )
49
+ } )
50
+ } )
51
+
52
+ it ( 'radio default value' , function ( ) {
53
+ var vm = new Vue ( {
54
+ el : el ,
55
+ data : { } ,
56
+ template : '<input type="radio" checked value="a" v-model="test">'
57
+ } )
58
+ expect ( vm . test ) . toBe ( 'a' )
59
+ } )
60
+
61
+ it ( 'checkbox' , function ( done ) {
62
+ var vm = new Vue ( {
63
+ el : el ,
64
+ data : {
65
+ test : true
66
+ } ,
67
+ template : '<input type="checkbox" v-model="test">'
68
+ } )
69
+ expect ( el . firstChild . checked ) . toBe ( true )
70
+ vm . test = false
71
+ _ . nextTick ( function ( ) {
72
+ expect ( el . firstChild . checked ) . toBe ( false )
73
+ expect ( vm . test ) . toBe ( false )
74
+ el . firstChild . click ( )
75
+ expect ( el . firstChild . checked ) . toBe ( true )
76
+ expect ( vm . test ) . toBe ( true )
77
+ vm . _directives [ 0 ] . unbind ( )
78
+ el . firstChild . click ( )
79
+ expect ( el . firstChild . checked ) . toBe ( false )
80
+ expect ( vm . test ) . toBe ( true )
81
+ done ( )
82
+ } )
83
+ } )
84
+
85
+ it ( 'checkbox default value' , function ( ) {
86
+ var vm = new Vue ( {
87
+ el : el ,
88
+ data : { } ,
89
+ template : '<input type="checkbox" checked v-model="test">'
90
+ } )
91
+ expect ( vm . test ) . toBe ( true )
92
+ } )
93
+
94
+ it ( 'select' , function ( ) {
95
+
96
+ } )
97
+
98
+ it ( 'select + options' , function ( ) {
99
+
100
+ } )
101
+
102
+ it ( 'text' , function ( ) {
103
+
104
+ } )
105
+
106
+ it ( 'text with filters' , function ( ) {
107
+
108
+ } )
109
+
110
+ it ( 'text + compositionevents' , function ( ) {
111
+
112
+ } )
113
+
114
+ it ( 'warn invalid' , function ( ) {
115
+ var vm = new Vue ( {
116
+ el : el ,
117
+ template : '<div v-model="test"></div<'
118
+ } )
119
+ expect ( _ . warn ) . toHaveBeenCalled ( )
120
+ } )
121
+
122
+ } )
123
+ }
0 commit comments