@@ -3,7 +3,8 @@ import Sortable from "sortablejs";
3
3
jest . genMockFromModule ( 'sortablejs' ) ;
4
4
jest . mock ( 'sortablejs' ) ;
5
5
const SortableFake = {
6
- destroy : jest . fn ( )
6
+ destroy : jest . fn ( ) ,
7
+ option : jest . fn ( )
7
8
} ;
8
9
Sortable . mockImplementation ( ( ) => SortableFake ) ;
9
10
import draggable from "@/vuedraggable" ;
@@ -24,10 +25,15 @@ function getEvent(name) {
24
25
return Sortable . mock . calls [ 0 ] [ 1 ] [ name ] ;
25
26
}
26
27
28
+ function resetMocks ( ) {
29
+ Sortable . mockClear ( ) ;
30
+ SortableFake . destroy . mockClear ( ) ;
31
+ SortableFake . option . mockClear ( ) ;
32
+ }
33
+
27
34
describe ( "draggable.vue when initialized with list" , ( ) => {
28
35
beforeEach ( ( ) => {
29
- Sortable . mockClear ( ) ;
30
- SortableFake . destroy . mockClear ( ) ;
36
+ resetMocks ( ) ;
31
37
items = [ "a" , "b" , "c" ] ;
32
38
wrapper = shallowMount ( draggable , {
33
39
attachToDocument : true ,
@@ -230,7 +236,7 @@ describe("draggable.vue when initialized with list", () => {
230
236
231
237
describe ( "when add is called" , ( ) => {
232
238
let newItem ;
233
- beforeEach ( async ( ) => {
239
+ beforeEach ( async ( ) => {
234
240
await Vue . nextTick ( ) ;
235
241
newItem = document . createElement ( "div" ) ;
236
242
const newContent = document . createTextNode ( "d" ) ;
@@ -387,16 +393,50 @@ describe("draggable.vue when initialized with list", () => {
387
393
} )
388
394
} ) ;
389
395
390
- it ( "does calls Sortable destroy when mounted" , ( ) => {
396
+ it ( "does calls Sortable destroy when mounted" , ( ) => {
391
397
expect ( SortableFake . destroy . mock . calls . length ) . toBe ( 0 ) ;
392
398
} ) ;
393
399
394
- it ( "calls Sortable destroy when destroyed" , ( ) => {
400
+ it ( "calls Sortable destroy when destroyed" , ( ) => {
395
401
wrapper . destroy ( ) ;
396
402
expect ( SortableFake . destroy ) . toHaveBeenCalled ( ) ;
397
403
expect ( SortableFake . destroy . mock . calls . length ) . toBe ( 1 ) ;
398
404
} ) ;
399
- } ) ;
405
+
406
+ describe ( "when attribute changes:" , ( ) => {
407
+ const { error } = console ;
408
+ beforeEach ( ( ) => {
409
+ console . error = ( ) => { } ;
410
+ } ) ;
411
+ afterEach ( ( ) => {
412
+ console . error = error ;
413
+ } )
414
+
415
+ test . each ( [
416
+ [ "sortableOption" , "newValue" , "sortableOption" ] ,
417
+ [ "to-be-camelized" , 1 , "toBeCamelized" ]
418
+ ] ) (
419
+ "attribute %s change for value %o, calls sortable option with %s attribute" ,
420
+ ( attribute , value , sortableAttribute ) => {
421
+ vm . $attrs = { [ attribute ] : value } ;
422
+ expect ( SortableFake . option ) . toHaveBeenCalledWith ( sortableAttribute , value ) ;
423
+ }
424
+ ) ;
425
+ } ) ;
426
+
427
+ test . each ( [
428
+ [ "sortableOption" , "newValue" , "sortableOption" ] ,
429
+ [ "to-be-camelized" , 1 , "toBeCamelized" ]
430
+ ] ) (
431
+ "when option %s change for value %o, calls sortable option with %s attribute" ,
432
+ ( attribute , value , sortableAttribute ) => {
433
+ wrapper . setProps ( { options : { [ attribute ] : value } } ) ;
434
+ expect ( SortableFake . option ) . toHaveBeenCalledWith ( sortableAttribute , value ) ;
435
+ }
436
+ ) ;
437
+
438
+ } )
439
+
400
440
401
441
describe ( "draggable.vue when initialized with value" , ( ) => {
402
442
beforeEach ( ( ) => {
0 commit comments