Skip to content

Commit ad5506f

Browse files
Improving tests
1 parent aa15146 commit ad5506f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/unit/vuedraggable.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,50 @@ describe("draggable.vue when initialized with modelValue", () => {
10681068
});
10691069
});
10701070

1071+
describe("when add is called on an empty list", () => {
1072+
let newItem;
1073+
beforeEach(async () => {
1074+
wrapper.setProps({ modelValue: [] });
1075+
1076+
await nextTick();
1077+
1078+
newItem = document.createElement("div");
1079+
const newContent = document.createTextNode("z");
1080+
newItem.appendChild(newContent);
1081+
newItem._underlying_vm_ = "z";
1082+
element.appendChild(newItem);
1083+
const add = getEvent("onAdd");
1084+
add({
1085+
item: newItem,
1086+
newIndex: 0
1087+
});
1088+
});
1089+
it("DOM should be reverted", async () => {
1090+
await nextTick();
1091+
expectHTML(wrapper, "<div></div>");
1092+
});
1093+
1094+
it("sends a update event", async () => {
1095+
await nextTick();
1096+
const expectedEvt = {
1097+
item: newItem,
1098+
newIndex: 0
1099+
};
1100+
expect(wrapper.emitted().add).toEqual([[expectedEvt]]);
1101+
});
1102+
1103+
it("sends a update:modelValue event", async () => {
1104+
await nextTick();
1105+
expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["z"]]);
1106+
});
1107+
1108+
it("sends a change event", async () => {
1109+
await nextTick();
1110+
const expectedEvt = { added: { element: "z", newIndex: 0 } };
1111+
expect(wrapper.emitted().change).toEqual([[expectedEvt]]);
1112+
});
1113+
});
1114+
10711115
describe("when update is called", () => {
10721116
beforeEach(() => {
10731117
const firstDraggable = element.children[0];

0 commit comments

Comments
 (0)