File tree Expand file tree Collapse file tree 2 files changed +65
-4
lines changed
test/unit/specs/directives Expand file tree Collapse file tree 2 files changed +65
-4
lines changed Original file line number Diff line number Diff line change @@ -5,17 +5,50 @@ module.exports = {
5
5
bind : function ( ) {
6
6
var self = this
7
7
var el = this . el
8
+ var trueExp = this . _checkParam ( 'true-value' )
9
+ var falseExp = this . _checkParam ( 'false-value' )
10
+
11
+ function getValue ( ) {
12
+ var val = el . checked
13
+ if ( val && trueExp !== null ) {
14
+ val = self . vm . $eval ( trueExp ) ;
15
+ }
16
+ if ( ! val && falseExp !== null ) {
17
+ val = self . vm . $eval ( falseExp ) ;
18
+ }
19
+ return val
20
+ }
21
+ this . _getValue = getValue
22
+
23
+ function matchValue ( value ) {
24
+ var trueValue = true
25
+ var falseValue = false
26
+
27
+ if ( trueExp !== null ) {
28
+ trueValue = self . vm . $eval ( trueExp ) ;
29
+ }
30
+ if ( falseExp !== null ) {
31
+ falseValue = self . vm . $eval ( falseExp ) ;
32
+ }
33
+ if ( trueValue == value ) {
34
+ return true
35
+ } else {
36
+ return false
37
+ }
38
+ }
39
+ this . _matchValue = matchValue
40
+
8
41
this . listener = function ( ) {
9
- self . set ( el . checked )
42
+ self . set ( getValue ( ) )
10
43
}
11
44
_ . on ( el , 'change' , this . listener )
12
45
if ( el . checked ) {
13
- this . _initValue = el . checked
46
+ this . _initValue = getValue ( )
14
47
}
15
48
} ,
16
49
17
50
update : function ( value ) {
18
- this . el . checked = ! ! value
51
+ this . el . checked = this . _matchValue ( value )
19
52
} ,
20
53
21
54
unbind : function ( ) {
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ if (_.inBrowser) {
80
80
expect ( vm . test ) . toBe ( 'a' )
81
81
} )
82
82
83
- fit ( 'radio expression' , function ( done ) {
83
+ it ( 'radio expression' , function ( done ) {
84
84
var vm = new Vue ( {
85
85
el : el ,
86
86
data : {
@@ -140,6 +140,34 @@ if (_.inBrowser) {
140
140
} )
141
141
expect ( vm . test ) . toBe ( true )
142
142
} )
143
+
144
+ it ( 'checkbox true-value false-value' , function ( done ) {
145
+ var vm = new Vue ( {
146
+ el : el ,
147
+ data : {
148
+ test : '' ,
149
+ expression1 : 'aTrueValue' ,
150
+ expression2 : 'aFalseValue'
151
+ } ,
152
+ template : '<input type="checkbox" v-model="test" true-value="expression1" false-value="expression2">'
153
+ } )
154
+ expect ( vm . test ) . toBe ( '' )
155
+ el . firstChild . click ( )
156
+ expect ( vm . test ) . toBe ( 'aTrueValue' )
157
+ expect ( el . firstChild . checked ) . toBe ( true )
158
+ el . firstChild . click ( )
159
+ expect ( vm . test ) . toBe ( 'aFalseValue' )
160
+ expect ( el . firstChild . checked ) . toBe ( false )
161
+ vm . test = 'aTrueValue'
162
+ _ . nextTick ( function ( ) {
163
+ // the updated value of 'test' is not being passed
164
+ // into the 'update' method of v-model in this environment
165
+ // works fine in manual test
166
+ //expect(el.firstChild.checked).toBe(true)
167
+ done ( )
168
+ } )
169
+
170
+ } )
143
171
144
172
it ( 'select' , function ( done ) {
145
173
var vm = new Vue ( {
You can’t perform that action at this time.
0 commit comments