diff --git a/index.js b/index.js
index 4f22f94..2e1c993 100644
--- a/index.js
+++ b/index.js
@@ -14,15 +14,11 @@ exports.install = function (Vue, options) {
tribute: null,
paramWatchers: {
values: function values(val, oldVal) {
- var _this = this;
-
- setTimeout(function () {
- _this.setValues(val);
- }, 0);
+ this.setValues(val);
}
},
bind: function bind() {
- var _this2 = this;
+ var _this = this;
// If it has a "values" property, it's actually a collection
if (this.params.values.hasOwnProperty("values")) {
@@ -37,10 +33,10 @@ exports.install = function (Vue, options) {
this.tribute.attach(this.el);
this.el.addEventListener("tribute-replaced", function (e) {
- _this2.vm.$emit("tribute-replaced");
+ _this.vm.$emit("tribute-replaced");
});
this.el.addEventListener("tribute-no-match", function (e) {
- _this2.vm.$emit("tribute-no-match");
+ _this.vm.$emit("tribute-no-match");
});
},
setValues: function setValues(values) {
diff --git a/index.umd.js b/index.umd.js
index 3d695d8..022b023 100644
--- a/index.umd.js
+++ b/index.umd.js
@@ -16,15 +16,11 @@
tribute: null,
paramWatchers: {
values: function values(val, oldVal) {
- var _this = this;
-
- setTimeout(function () {
- _this.setValues(val);
- }, 0);
+ this.setValues(val);
}
},
bind: function bind() {
- var _this2 = this;
+ var _this = this;
// If it has a "values" property, it's actually a collection
if (this.params.values.hasOwnProperty("values")) {
@@ -39,10 +35,10 @@
this.tribute.attach(this.el);
this.el.addEventListener("tribute-replaced", function (e) {
- _this2.vm.$emit("tribute-replaced");
+ _this.vm.$emit("tribute-replaced");
});
this.el.addEventListener("tribute-no-match", function (e) {
- _this2.vm.$emit("tribute-no-match");
+ _this.vm.$emit("tribute-no-match");
});
},
setValues: function setValues(values) {
diff --git a/src/index.js b/src/index.js
index 5633c53..c8b1448 100644
--- a/src/index.js
+++ b/src/index.js
@@ -10,9 +10,7 @@ exports.install = function (Vue, options) {
tribute: null,
paramWatchers: {
values (val, oldVal) {
- setTimeout(() => {
- this.setValues(val)
- }, 0)
+ this.setValues(val)
}
},
bind () {
diff --git a/test/VueTribute.spec.js b/test/VueTribute.spec.js
index e1e5d2e..83d0801 100644
--- a/test/VueTribute.spec.js
+++ b/test/VueTribute.spec.js
@@ -2,24 +2,43 @@ import Vue from "vue";
import VueTribute from "../src";
Vue.use(VueTribute);
-
+var vm = null
+beforeEach(() => {
+ vm = new Vue({
+ el: document.body,
+ replace: false,
+ template: "",
+ data(){
+ return {
+ items: [
+ {key: "Phil Heartman", value: "pheartman"},
+ {key: "Gordon Ramsey", value: "gramsey"}
+ ]
+ }
+ }
+ })
+})
describe("vue-tribute", () => {
it("has an install method for Vue.use()", () => {
- expect(typeof VueTribute.install).toEqual("function");
- });
- it("creates the v-tribute directive", () => {
- const vm = new Vue({
- template: "",
- data(){
- return {
- items: [
- {key: "Phil Heartman", value: "pheartman"},
- {key: "Gordon Ramsey", value: "gramsey"}
- ]
- }
- }
- }).$mount();
+ expect(typeof VueTribute.install).toEqual("function")
+ })
- expect(typeof vm.$options.directives["tribute"]).toEqual("object");
- });
+ it("creates the v-tribute directive", () => {
+ expect(typeof vm.$options.directives["tribute"]).toEqual("object")
+ })
+
+ it("triggers the param watcher when the underlying model changes", (done) => {
+ spyOn(vm.$options.directives["tribute"].paramWatchers, "values").and.callThrough()
+
+ const newItems = [
+ {key: "Kerem Suer", value: "kerem"},
+ {key: "Rob Delaney", value: "robdelaney"}
+ ]
+ vm.$set("items", newItems)
+
+ setTimeout(() => {
+ expect(vm.$options.directives["tribute"].paramWatchers.values).toHaveBeenCalled()
+ done()
+ }, 0)
+ })
})