Skip to content

Commit 618daa0

Browse files
Improving tests
1 parent 2b1bd9f commit 618daa0

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@
9595
"testMatch": [
9696
"**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
9797
],
98-
"testURL": "http://localhost/"
98+
"testURL": "http://localhost/",
99+
"collectCoverageFrom": [
100+
"<rootDir>/src/vuedraggable.js"
101+
]
99102
},
100103
"files": [
101104
"dist/*.css",

tests/unit/helper/FakeComponent.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
name: "Fake",
3+
props: {
4+
prop1: {
5+
type: String,
6+
default: "string"
7+
}
8+
},
9+
template: "<div>{{prop1}}</div>"
10+
}

tests/unit/vuedraggable.spec.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { shallowMount } from "@vue/test-utils";
1+
import { mount, shallowMount } from "@vue/test-utils";
22
import Sortable from "sortablejs";
33
jest.genMockFromModule('sortablejs');
44
jest.mock('sortablejs');
@@ -7,12 +7,14 @@ const SortableFake = {
77
Sortable.mockImplementation(() => SortableFake);
88
import draggable from "@/vuedraggable";
99
import Vue from "vue";
10+
import Fake from "./helper/FakeComponent.js"
1011

1112
let wrapper;
1213
let vm;
1314
let props;
1415
let items;
1516
let element;
17+
let input;
1618

1719
describe("draggable.vue", () => {
1820
beforeEach(() => {
@@ -123,6 +125,46 @@ describe("draggable.vue", () => {
123125
}
124126
)
125127

128+
describe("when using component as tag", () => {
129+
beforeEach(() => {
130+
input = jest.fn();
131+
wrapper = mount(draggable, {
132+
propsData: {
133+
tag: "child",
134+
componentData: {
135+
on: {
136+
input
137+
},
138+
props: {
139+
prop1: "info",
140+
prop2: true
141+
}
142+
}
143+
},
144+
stubs: {
145+
child: Fake
146+
}
147+
});
148+
});
149+
150+
it("instantiate child component", async () => {
151+
const child = wrapper.find(Fake);
152+
expect(child).not.toBeNull();
153+
})
154+
155+
it("pass data to tag child", async () => {
156+
const fakeChild = wrapper.find(Fake);
157+
expect(fakeChild.props("prop1")).toEqual("info");
158+
})
159+
160+
it("pass data to tag child", async () => {
161+
const child = wrapper.find(Fake);
162+
const evt = { data: 33 };
163+
child.vm.$emit('input', evt);
164+
expect(input).toHaveBeenCalledWith(evt);
165+
})
166+
});
167+
126168
it("keeps a reference to Sortable instance", () => {
127169
expect(vm._sortable).toBe(SortableFake);
128170
})

0 commit comments

Comments
 (0)