File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
packages/runtime-dom/__tests__/directives Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 5
5
nextTick ,
6
6
ref ,
7
7
render ,
8
+ vModelCheckbox ,
8
9
vModelDynamic ,
9
10
withDirectives ,
10
11
} from '@vue/runtime-dom'
@@ -1445,4 +1446,51 @@ describe('vModel', () => {
1445
1446
1446
1447
expect ( inputNum1 . value ) . toBe ( '1' )
1447
1448
} )
1449
+
1450
+ it ( `should support mutating an array or set value for a checkbox` , async ( ) => {
1451
+ const component = defineComponent ( {
1452
+ data ( ) {
1453
+ return { value : [ ] }
1454
+ } ,
1455
+ render ( ) {
1456
+ return [
1457
+ withDirectives (
1458
+ h ( 'input' , {
1459
+ type : 'checkbox' ,
1460
+ class : 'foo' ,
1461
+ value : 'foo' ,
1462
+ 'onUpdate:modelValue' : setValue . bind ( this ) ,
1463
+ } ) ,
1464
+ [ [ vModelCheckbox , this . value ] ] ,
1465
+ ) ,
1466
+ ]
1467
+ } ,
1468
+ } )
1469
+ render ( h ( component ) , root )
1470
+
1471
+ const foo = root . querySelector ( '.foo' )
1472
+ const data = root . _vnode . component . data
1473
+
1474
+ expect ( foo . checked ) . toEqual ( false )
1475
+
1476
+ data . value . push ( 'foo' )
1477
+ await nextTick ( )
1478
+ expect ( foo . checked ) . toEqual ( true )
1479
+
1480
+ data . value [ 0 ] = 'bar'
1481
+ await nextTick ( )
1482
+ expect ( foo . checked ) . toEqual ( false )
1483
+
1484
+ data . value = new Set ( )
1485
+ await nextTick ( )
1486
+ expect ( foo . checked ) . toEqual ( false )
1487
+
1488
+ data . value . add ( 'foo' )
1489
+ await nextTick ( )
1490
+ expect ( foo . checked ) . toEqual ( true )
1491
+
1492
+ data . value . delete ( 'foo' )
1493
+ await nextTick ( )
1494
+ expect ( foo . checked ) . toEqual ( false )
1495
+ } )
1448
1496
} )
You can’t perform that action at this time.
0 commit comments