diff --git a/src/watcher.js b/src/watcher.js index 96b142c0ec3..96169f37d22 100644 --- a/src/watcher.js +++ b/src/watcher.js @@ -233,11 +233,11 @@ Watcher.prototype.run = function () { var value = this.get() if ( value !== this.value || - // Deep watchers and Array watchers should fire even + // Deep watchers and watchers on Object/Arrays should fire even // when the value is the same, because the value may // have mutated; but only do so if this is a // non-shallow update (caused by a vm digest). - ((isArray(value) || this.deep) && !this.shallow) + ((isObject(value) || this.deep) && !this.shallow) ) { // set new value var oldValue = this.value diff --git a/test/unit/specs/watcher_spec.js b/test/unit/specs/watcher_spec.js index 1b69224d34b..1a501bf661c 100644 --- a/test/unit/specs/watcher_spec.js +++ b/test/unit/specs/watcher_spec.js @@ -289,6 +289,20 @@ describe('Watcher', function () { }) }) + it('fire change for prop addition/deletion in non-deep mode', function (done) { + new Watcher(vm, 'b', spy) + Vue.set(vm.b, 'e', 123) + nextTick(function () { + expect(spy).toHaveBeenCalledWith(vm.b, vm.b) + expect(spy.calls.count()).toBe(1) + Vue.delete(vm.b, 'e') + nextTick(function () { + expect(spy.calls.count()).toBe(2) + done() + }) + }) + }) + it('watch function', function (done) { var watcher = new Watcher(vm, function () { return this.a + this.b.d