Skip to content

Commit 6c13234

Browse files
Adding tests
1 parent 1d26f3c commit 6c13234

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

tests/unit/vuedraggable.spec.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,11 +1574,36 @@ describe("when using a fragment component as tag", () => {
15741574
const parameters = Sortable.mock.calls[0];
15751575
expect(parameters[0]).toBe(element);
15761576
});
1577+
});
1578+
1579+
describe.each([
1580+
["a", ["a", "b"]],
1581+
["n", [0, 1]],
1582+
[({ a, n }) => `${a}-${n}`, ["a-0", "b-1"]]
1583+
])("when using %p as item-key", (itemKey, expected) => {
1584+
beforeEach(async () => {
1585+
resetMocks();
15771586

1578-
it("sets nodes keys", () => {
1579-
const keys = [0, 1, 2]
1587+
wrapper = mount(draggable, {
1588+
props: {
1589+
list: [
1590+
{ a: "a", n: 0 },
1591+
{ a: "b", n: 1 }
1592+
],
1593+
itemKey
1594+
},
1595+
slots: {
1596+
item: ({ element }) => {
1597+
return h("div", null, element);
1598+
}
1599+
}
1600+
});
1601+
element = wrapper.element;
1602+
});
1603+
it("sets nodes keys accordingly", () => {
1604+
const keys = [0, 1]
15801605
.map(index => element.children.item(index))
15811606
.map(el => el.__vnode.key);
1582-
expect(keys).toEqual(["a", "b", "c"]);
1607+
expect(keys).toEqual(expected);
15831608
});
1584-
});
1609+
})

0 commit comments

Comments
 (0)