1
1
import { shallowMount } from "@vue/test-utils" ;
2
2
import Sortable from "sortablejs" ;
3
-
3
+ jest . genMockFromModule ( 'sortablejs' ) ;
4
+ jest . mock ( 'sortablejs' ) ;
5
+ const SortableFake = {
6
+ } ;
7
+ Sortable . mockImplementation ( ( ) => SortableFake ) ;
4
8
import draggable from "@/vuedraggable" ;
5
9
6
10
let wrapper ;
@@ -11,12 +15,12 @@ let html;
11
15
12
16
describe ( "draggable.vue" , ( ) => {
13
17
beforeEach ( ( ) => {
14
- items = [ "a" , "b" , "c" ] ;
15
- wrapper = shallowMount ( draggable , {
16
- propsData :{
18
+ items = [ "a" , "b" , "c" ] ;
19
+ wrapper = shallowMount ( draggable , {
20
+ propsData : {
17
21
list : items
18
22
} ,
19
- slots :{
23
+ slots : {
20
24
default : items . map ( item => `<div>${ item } </div>` ) ,
21
25
header : "<header/>" ,
22
26
footer : "<footer/>"
@@ -91,6 +95,10 @@ describe("draggable.vue", () => {
91
95
expect ( wrapper . html ( ) ) . toMatch ( / ^ < d i v > < h e a d e r > < \/ h e a d e r > / ) ;
92
96
} )
93
97
98
+ it ( "renders default slot element correctly" , ( ) => {
99
+ expect ( wrapper . html ( ) ) . toContain ( "<div>a</div><div>b</div><div>c</div>" ) ;
100
+ } )
101
+
94
102
test . each ( [
95
103
"ul" ,
96
104
"span" ,
@@ -105,4 +113,8 @@ describe("draggable.vue", () => {
105
113
expect ( wrapper . html ( ) ) . toMatch ( expectedRegex ) ;
106
114
}
107
115
)
116
+
117
+ it ( "keeps a reference to Sortable instance" , ( ) => {
118
+ expect ( vm . _sortable ) . toBe ( SortableFake ) ;
119
+ } )
108
120
} ) ;
0 commit comments