Skip to content

Commit b457b69

Browse files
Improving tests
1 parent 7239aaf commit b457b69

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/unit/vuedraggable.spec.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { shallowMount } from "@vue/test-utils";
22
import Sortable from "sortablejs";
3-
3+
jest.genMockFromModule('sortablejs');
4+
jest.mock('sortablejs');
5+
const SortableFake = {
6+
};
7+
Sortable.mockImplementation(() => SortableFake);
48
import draggable from "@/vuedraggable";
59

610
let wrapper;
@@ -11,12 +15,12 @@ let html;
1115

1216
describe("draggable.vue", () => {
1317
beforeEach(() => {
14-
items= ["a", "b", "c"];
15-
wrapper = shallowMount(draggable,{
16-
propsData:{
18+
items = ["a", "b", "c"];
19+
wrapper = shallowMount(draggable, {
20+
propsData: {
1721
list: items
1822
},
19-
slots:{
23+
slots: {
2024
default: items.map(item => `<div>${item}</div>`),
2125
header: "<header/>",
2226
footer: "<footer/>"
@@ -91,6 +95,10 @@ describe("draggable.vue", () => {
9195
expect(wrapper.html()).toMatch(/^<div><header><\/header>/);
9296
})
9397

98+
it("renders default slot element correctly", () => {
99+
expect(wrapper.html()).toContain("<div>a</div><div>b</div><div>c</div>");
100+
})
101+
94102
test.each([
95103
"ul",
96104
"span",
@@ -105,4 +113,8 @@ describe("draggable.vue", () => {
105113
expect(wrapper.html()).toMatch(expectedRegex);
106114
}
107115
)
116+
117+
it("keeps a reference to Sortable instance", () => {
118+
expect(vm._sortable).toBe(SortableFake);
119+
})
108120
});

0 commit comments

Comments
 (0)