Skip to content

Commit 8ad33e5

Browse files
Adding tests
1 parent 7d57d56 commit 8ad33e5

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

tests/unit/vuedraggable.spec.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe("draggable.vue when initialized with list", () => {
6969
element = wrapper.element;
7070
});
7171

72-
describe("when initialized with incorrect props", () => {
72+
describe("in case of misuse", () => {
7373
const { error } = console;
7474
const { warn } = console;
7575

@@ -83,15 +83,15 @@ describe("draggable.vue when initialized with list", () => {
8383
console.warn = warn;
8484
});
8585

86-
it("log an error when list and value are both not null", () => {
86+
it("logs an error when list and value are both not null when initialized with incorrect props", () => {
8787
wrapper = mount(draggable, {
8888
props: {
8989
list: [],
9090
modelValue: [],
9191
itemKey: k => k
9292
},
9393
slots: {
94-
item: ({element}) => h("div", null, element)
94+
item: ({ element }) => h("div", null, element)
9595
}
9696
});
9797
expect(console.error).toBeCalledWith(
@@ -112,7 +112,27 @@ describe("draggable.vue when initialized with list", () => {
112112
expect(wrapper.html()).toContain(
113113
"Error: draggable element must have an item slot"
114114
);
115-
})
115+
});
116+
117+
it("renders an error when item slot render multiple nodes", () => {
118+
wrapper = mount(draggable, {
119+
props: {
120+
list: [1],
121+
modelValue: [],
122+
itemKey: k => k
123+
},
124+
slots: {
125+
item: ({ element, index }) => {
126+
return [h("div", null, element), h("span", null, index)];
127+
}
128+
}
129+
});
130+
131+
expect(wrapper.element.nodeName).toEqual("PRE");
132+
expect(wrapper.html()).toContain(
133+
"Error: Item slot must have only one child"
134+
);
135+
});
116136
});
117137

118138
it("instantiate without error", () => {

0 commit comments

Comments
 (0)