@@ -1068,6 +1068,50 @@ describe("draggable.vue when initialized with modelValue", () => {
1068
1068
} ) ;
1069
1069
} ) ;
1070
1070
1071
+ describe ( "when add is called on an empty list" , ( ) => {
1072
+ let newItem ;
1073
+ beforeEach ( async ( ) => {
1074
+ wrapper . setProps ( { modelValue : [ ] } ) ;
1075
+
1076
+ await nextTick ( ) ;
1077
+
1078
+ newItem = document . createElement ( "div" ) ;
1079
+ const newContent = document . createTextNode ( "z" ) ;
1080
+ newItem . appendChild ( newContent ) ;
1081
+ newItem . _underlying_vm_ = "z" ;
1082
+ element . appendChild ( newItem ) ;
1083
+ const add = getEvent ( "onAdd" ) ;
1084
+ add ( {
1085
+ item : newItem ,
1086
+ newIndex : 0
1087
+ } ) ;
1088
+ } ) ;
1089
+ it ( "DOM should be reverted" , async ( ) => {
1090
+ await nextTick ( ) ;
1091
+ expectHTML ( wrapper , "<div></div>" ) ;
1092
+ } ) ;
1093
+
1094
+ it ( "sends a update event" , async ( ) => {
1095
+ await nextTick ( ) ;
1096
+ const expectedEvt = {
1097
+ item : newItem ,
1098
+ newIndex : 0
1099
+ } ;
1100
+ expect ( wrapper . emitted ( ) . add ) . toEqual ( [ [ expectedEvt ] ] ) ;
1101
+ } ) ;
1102
+
1103
+ it ( "sends a update:modelValue event" , async ( ) => {
1104
+ await nextTick ( ) ;
1105
+ expect ( wrapper . emitted ( ) [ "update:modelValue" ] [ 0 ] ) . toEqual ( [ [ "z" ] ] ) ;
1106
+ } ) ;
1107
+
1108
+ it ( "sends a change event" , async ( ) => {
1109
+ await nextTick ( ) ;
1110
+ const expectedEvt = { added : { element : "z" , newIndex : 0 } } ;
1111
+ expect ( wrapper . emitted ( ) . change ) . toEqual ( [ [ expectedEvt ] ] ) ;
1112
+ } ) ;
1113
+ } ) ;
1114
+
1071
1115
describe ( "when update is called" , ( ) => {
1072
1116
beforeEach ( ( ) => {
1073
1117
const firstDraggable = element . children [ 0 ] ;
0 commit comments