File tree 2 files changed +15
-11
lines changed
2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ describe('vModel', () => {
280
280
it ( 'should work with checkbox and true-value/false-value' , async ( ) => {
281
281
const component = defineComponent ( {
282
282
data ( ) {
283
- return { value : null }
283
+ return { value : 'yes' }
284
284
} ,
285
285
render ( ) {
286
286
return [
@@ -301,23 +301,26 @@ describe('vModel', () => {
301
301
const input = root . querySelector ( 'input' )
302
302
const data = root . _vnode . component . data
303
303
304
- input . checked = true
305
- triggerEvent ( 'change' , input )
306
- await nextTick ( )
307
- expect ( data . value ) . toEqual ( 'yes' )
304
+ // DOM checked state should respect initial true-value/false-value
305
+ expect ( input . checked ) . toEqual ( true )
308
306
309
- data . value = 'no'
307
+ input . checked = false
308
+ triggerEvent ( 'change' , input )
310
309
await nextTick ( )
311
- expect ( input . checked ) . toEqual ( false )
310
+ expect ( data . value ) . toEqual ( 'no' )
312
311
313
312
data . value = 'yes'
314
313
await nextTick ( )
315
314
expect ( input . checked ) . toEqual ( true )
316
315
317
- input . checked = false
316
+ data . value = 'no'
317
+ await nextTick ( )
318
+ expect ( input . checked ) . toEqual ( false )
319
+
320
+ input . checked = true
318
321
triggerEvent ( 'change' , input )
319
322
await nextTick ( )
320
- expect ( data . value ) . toEqual ( 'no ' )
323
+ expect ( data . value ) . toEqual ( 'yes ' )
321
324
} )
322
325
323
326
it ( 'should work with checkbox and true-value/false-value with object values' , async ( ) => {
Original file line number Diff line number Diff line change @@ -99,8 +99,7 @@ export const vModelText: ModelDirective<
99
99
}
100
100
101
101
export const vModelCheckbox : ModelDirective < HTMLInputElement > = {
102
- created ( el , binding , vnode ) {
103
- setChecked ( el , binding , vnode )
102
+ created ( el , _ , vnode ) {
104
103
el . _assign = getModelAssigner ( vnode )
105
104
addEventListener ( el , 'change' , ( ) => {
106
105
const modelValue = ( el as any ) . _modelValue
@@ -130,6 +129,8 @@ export const vModelCheckbox: ModelDirective<HTMLInputElement> = {
130
129
}
131
130
} )
132
131
} ,
132
+ // set initial checked on mount to wait for true-value/false-value
133
+ mounted : setChecked ,
133
134
beforeUpdate ( el , binding , vnode ) {
134
135
el . _assign = getModelAssigner ( vnode )
135
136
setChecked ( el , binding , vnode )
You can’t perform that action at this time.
0 commit comments