2
0
mirror of https://github.com/tenrok/vue-tribute.git synced 2026-06-24 12:20:35 +03:00

Test for separate items and options

This commit is contained in:
au
2016-12-07 19:59:46 +01:00
parent 7034282bed
commit 62aa6aa6cd
+15 -6
View File
@@ -7,7 +7,10 @@ beforeEach(() => {
vm = new Vue({ vm = new Vue({
el: document.body, el: document.body,
replace: false, replace: false,
template: "<input type='text' :values='items' v-tribute />", template: `<input type='text'
v-tribute='items'
:tributeoptions='{trigger: "#"}'
/>`,
data(){ data(){
return { return {
items: [ items: [
@@ -27,8 +30,14 @@ describe("vue-tribute", () => {
expect(typeof vm.$options.directives["tribute"]).toEqual("object") expect(typeof vm.$options.directives["tribute"]).toEqual("object")
}) })
it("triggers the param watcher when the underlying model changes", (done) => { it("supports tribute options", () => {
spyOn(vm.$options.directives["tribute"].paramWatchers, "values").and.callThrough() expect(vm._directives[0].tribute.collection[0].trigger).toEqual("#")
})
it("updates the items when the underlying model changes", (done) => {
const directive = vm._directives[0]
expect(directive.tribute.collection[0].values).toEqual(vm.items)
const newItems = [ const newItems = [
{key: "Kerem Suer", value: "kerem"}, {key: "Kerem Suer", value: "kerem"},
@@ -36,9 +45,9 @@ describe("vue-tribute", () => {
] ]
vm.$set("items", newItems) vm.$set("items", newItems)
setTimeout(() => { Vue.nextTick(() => {
expect(vm.$options.directives["tribute"].paramWatchers.values).toHaveBeenCalled() expect(directive.tribute.collection[0].values).toEqual(newItems)
done() done()
}, 0) })
}) })
}) })