Просмотр исходного кода

fix #468 dynamic literals with falsy initial value

Evan You 11 лет назад
Родитель
Сommit
a5966e8f85
2 измененных файлов с 7 добавлено и 5 удалено
  1. 1 1
      src/directive.js
  2. 6 4
      test/unit/specs/directive_spec.js

+ 1 - 1
src/directive.js

@@ -61,7 +61,7 @@ p._bind = function (def) {
     this.bind()
   }
   if (
-    this.expression && this.update &&
+    this.update && this._watcherExp &&
     (!this.isLiteral || this._isDynamicLiteral) &&
     !this._checkExpFn()
   ) {

+ 6 - 4
test/unit/specs/directive_spec.js

@@ -80,17 +80,19 @@ describe('Directive', function () {
   })
 
   it('dynamic literal', function (done) {
+    vm.a = '' // #468 dynamic literals with falsy initial
+              // should still create the watcher.
     def.isLiteral = true
     var d = new Directive('test', el, vm, {
       expression: '{{a}}'
     }, def)
     expect(d._watcher).toBeDefined()
-    expect(d.expression).toBe(1)
+    expect(d.expression).toBe('')
     expect(def.bind).toHaveBeenCalled()
-    expect(def.update).toHaveBeenCalledWith(1)
-    vm.a = 2
+    expect(def.update).toHaveBeenCalledWith('')
+    vm.a = 'aa'
     nextTick(function () {
-      expect(def.update).toHaveBeenCalledWith(2, 1)
+      expect(def.update).toHaveBeenCalledWith('aa', '')
       done()
     })
   })