Skip to content

Commit f27a20e

Browse files
Adding test
1 parent 709b801 commit f27a20e

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

src/core/componentStructure.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class ComponentStructure {
3838
this.noneFunctional =
3939
this.externalComponent && typeof this.tag !== "function";
4040
this.setHtmlRoot($el);
41-
this._checkCoherence();
4241
}
4342

4443
setHtmlRoot($el) {
@@ -57,14 +56,6 @@ class ComponentStructure {
5756
return this._getChildrenNodes().map(getHtmlElementFromNode);
5857
}
5958

60-
_checkCoherence() {
61-
if (this.noneFunctional && this.transitionMode) {
62-
throw new Error(
63-
`Transition-group inside component is not supported. Please alter tag value or remove transition-group. Current tag value: ${this.tag}`
64-
);
65-
}
66-
}
67-
6859
_getChildrenNodes() {
6960
const {
7061
noneFunctional,
@@ -73,7 +64,6 @@ class ComponentStructure {
7364
} = this;
7465

7566
if (noneFunctional) {
76-
//TODO check problem here
7767
return defaultNodes[0].children;
7868
}
7969

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<draggable
3+
:list="array"
4+
tag="fake"
5+
:component-data="{ props: { prop1: 'my-id' } }"
6+
>
7+
<div v-for="item in array" :key="item">{{ item }}</div>
8+
</draggable>
9+
</template>
10+
<script>
11+
import draggable from "@/vuedraggable";
12+
13+
export default {
14+
components: {
15+
draggable
16+
},
17+
data() {
18+
return {
19+
array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
20+
};
21+
}
22+
};
23+
</script>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default {
2-
name: "Fake",
2+
name: "FakeRoot",
33
props: {
44
prop1: {
55
type: String,
66
default: "string"
77
}
88
},
9-
template: "<div>{{prop1}}</div>"
9+
template: `<div class="fake-root" :id="prop1"><slot></slot></div>`
1010
}

tests/unit/vuedraggable.integrated.spec.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ Sortable.mockImplementation(() => SortableFake);
1111

1212
import { nextTick } from "vue";
1313
import DraggableWithList from "./helper/DraggableWithList";
14+
import DraggableWithComponent from "./helper/DraggableWithComponent.vue";
1415
import DraggableWithModel from "./helper/DraggableWithList";
1516
import DraggableWithTransition from "./helper/DraggableWithTransition";
17+
import fake from "./helper/FakeRoot";
1618

1719
import draggable from "@/vuedraggable";
1820

@@ -25,13 +27,17 @@ function getEvent(name) {
2527
}
2628

2729
const expectedArray = [0, 1, 3, 4, 5, 6, 7, 2, 8, 9];
28-
const expectedDomWithWrapper = wrapper =>
29-
`<${wrapper}>${expectedArray
30-
.map(nu => `<div>${nu}</div>`)
30+
const expectedDomWithWrapper = (wrapper, attr = "") =>
31+
`<${wrapper}${attr}>${expectedArray
32+
.map((nu) => `<div>${nu}</div>`)
3133
.join("")}</${wrapper}>`;
3234

3335
const expectedDomNoTransition = expectedDomWithWrapper("span");
3436
const expectedDomTransition = expectedDomWithWrapper("div");
37+
const expectedDomComponent = expectedDomWithWrapper(
38+
"div",
39+
'class="fake-root"id="my-id"'
40+
);
3541

3642
function normalizeHTML(wrapper) {
3743
return wrapper.html().replace(/(\r\n\t|\n|\r\t| )/gm, "");
@@ -45,6 +51,12 @@ function expectHTML(wrapper, expected) {
4551
describe.each([
4652
["draggable with list", DraggableWithList, expectedDomNoTransition, "span"],
4753
["draggable with model", DraggableWithModel, expectedDomNoTransition, "span"],
54+
[
55+
"draggable with list and component as tag",
56+
DraggableWithComponent,
57+
expectedDomComponent,
58+
"div"
59+
],
4860
[
4961
"draggable with transition",
5062
DraggableWithTransition,
@@ -57,7 +69,13 @@ describe.each([
5769
describe("when handling sort", () => {
5870
beforeEach(async () => {
5971
jest.resetAllMocks();
60-
wrapper = mount(component);
72+
wrapper = mount(component, {
73+
global: {
74+
components: {
75+
fake
76+
}
77+
}
78+
});
6179
vm = wrapper.vm;
6280
element = wrapper.find(expectWrapper).element;
6381

tests/unit/vuedraggable.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { mount, config } from "@vue/test-utils";
2-
//config.global.stubs["transition-group"] = false;
32
import Sortable from "sortablejs";
43
jest.genMockFromModule("sortablejs");
54
jest.mock("sortablejs");
@@ -11,7 +10,7 @@ Sortable.mockImplementation(() => SortableFake);
1110
import draggable from "@/vuedraggable";
1211
import { nextTick, h } from "vue";
1312

14-
import Fake from "./helper/FakeComponent.js";
13+
import Fake from "./helper/FakeRoot.js";
1514
import DraggableOption from "./helper/DraggableOption.vue";
1615
import FakeFunctional from "./helper/FakeFunctionalComponent.js";
1716

0 commit comments

Comments
 (0)