Skip to content

Commit 2bb8895

Browse files
Improving tests
1 parent 0a609b2 commit 2bb8895

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

src/vuedraggable.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ const draggableComponent = {
162162
return h(this.getTag(), attributes, children);
163163
},
164164

165-
renderError (h, err) {
166-
return h('pre', { style: { color: 'red' }}, err.stack)
167-
},
168-
169165
created() {
170166
if (this.list !== null && this.value !== null) {
171167
console.error(

tests/unit/vuedraggable.spec.js

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,64 @@ describe("draggable.vue when initialized with list", () => {
5656
element = wrapper.element;
5757
});
5858

59+
describe("when initialized with incorrect props", () => {
60+
const { error } = console;
61+
const { warn } = console;
62+
63+
beforeEach(() => {
64+
console.error = jest.fn();
65+
console.warn = jest.fn();
66+
});
67+
68+
afterEach(() => {
69+
console.error = error;
70+
console.warn = warn;
71+
})
72+
73+
it("log an error when list and value are both not null", () => {
74+
wrapper = shallowMount(draggable, {
75+
attachToDocument: true,
76+
propsData: {
77+
list: [],
78+
value: []
79+
},
80+
slots: {
81+
default: ""
82+
}
83+
});
84+
expect(console.error).toBeCalledWith("Value and list props are mutually exclusive! Please set one or another.");
85+
});
86+
87+
it("warns when options is used", () => {
88+
wrapper = shallowMount(draggable, {
89+
attachToDocument: true,
90+
propsData: {
91+
options: {
92+
group: "led zeppelin"
93+
}
94+
},
95+
slots: {
96+
default: ""
97+
}
98+
});
99+
expect(console.warn).toBeCalledWith("Options props is deprecated, add sortable options directly as vue.draggable item, or use v-bind. See https://github.com/SortableJS/Vue.Draggable/blob/master/documentation/migrate.md#options-props");
100+
});
101+
102+
it("warns when element is used", () => {
103+
wrapper = shallowMount(draggable, {
104+
attachToDocument: true,
105+
propsData: {
106+
element: "li"
107+
},
108+
slots: {
109+
default: ""
110+
}
111+
});
112+
expect(console.warn).toBeCalledWith( "Element props is deprecated please use tag props instead. See https://github.com/SortableJS/Vue.Draggable/blob/master/documentation/migrate.md#element-props");
113+
});
114+
115+
});
116+
59117
it("instantiate without error", () => {
60118
expect(wrapper).not.toBeUndefined();
61119
});
@@ -157,7 +215,7 @@ describe("draggable.vue when initialized with list", () => {
157215
await Vue.nextTick();
158216
const computeIndexes = jest.fn();
159217
wrapper.setMethods({ computeIndexes })
160-
wrapper.setProps({list: ["c", "d", "e", "f", "g"]});
218+
wrapper.setProps({ list: ["c", "d", "e", "f", "g"] });
161219
expect(computeIndexes).toHaveBeenCalled()
162220
});
163221

@@ -592,7 +650,7 @@ describe("draggable.vue when initialized with value", () => {
592650
await Vue.nextTick();
593651
const computeIndexes = jest.fn();
594652
wrapper.setMethods({ computeIndexes })
595-
wrapper.setProps({value: ["c", "d", "e", "f", "g"]});
653+
wrapper.setProps({ value: ["c", "d", "e", "f", "g"] });
596654
expect(computeIndexes).toHaveBeenCalled()
597655
});
598656

@@ -728,7 +786,7 @@ describe("draggable.vue when initialized with a transition group", () => {
728786
Sortable.mockClear();
729787
items = ["a", "b", "c"];
730788
const inside = items.map(item => `<div>${item}</div>`).join("");
731-
const template =`<transition-group>${inside}</transition-group>`
789+
const template = `<transition-group>${inside}</transition-group>`
732790
wrapper = shallowMount(draggable, {
733791
attachToDocument: true,
734792
propsData: {

0 commit comments

Comments
 (0)