Skip to content

Commit a5966e8

Browse files
committed
fix #468 dynamic literals with falsy initial value
1 parent 2017704 commit a5966e8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ p._bind = function (def) {
6161
this.bind()
6262
}
6363
if (
64-
this.expression && this.update &&
64+
this.update && this._watcherExp &&
6565
(!this.isLiteral || this._isDynamicLiteral) &&
6666
!this._checkExpFn()
6767
) {

test/unit/specs/directive_spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,19 @@ describe('Directive', function () {
8080
})
8181

8282
it('dynamic literal', function (done) {
83+
vm.a = '' // #468 dynamic literals with falsy initial
84+
// should still create the watcher.
8385
def.isLiteral = true
8486
var d = new Directive('test', el, vm, {
8587
expression: '{{a}}'
8688
}, def)
8789
expect(d._watcher).toBeDefined()
88-
expect(d.expression).toBe(1)
90+
expect(d.expression).toBe('')
8991
expect(def.bind).toHaveBeenCalled()
90-
expect(def.update).toHaveBeenCalledWith(1)
91-
vm.a = 2
92+
expect(def.update).toHaveBeenCalledWith('')
93+
vm.a = 'aa'
9294
nextTick(function () {
93-
expect(def.update).toHaveBeenCalledWith(2, 1)
95+
expect(def.update).toHaveBeenCalledWith('aa', '')
9496
done()
9597
})
9698
})

0 commit comments

Comments
 (0)