Skip to content

Commit 78d6abe

Browse files
committed
tests for attribute interpolation
1 parent 97754de commit 78d6abe

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/directives/public/bind.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ module.exports = {
4545
'in valid native attributes. "' + attr + '" ' +
4646
'is not a valid attribute on <' + this.el.tagName.toLowerCase() + '>.'
4747
)
48+
this.el.removeAttribute(attr)
4849
this.invalid = true
4950
}
5051

52+
/* istanbul ignore if */
5153
if (process.env.NODE_ENV !== 'production') {
5254
var raw = attr + '="' + this.descriptor.raw + '": '
5355
// warn src
@@ -71,7 +73,9 @@ module.exports = {
7173
},
7274

7375
update: function (value) {
74-
if (this.invalid) return
76+
if (this.invalid) {
77+
return
78+
}
7579
var attr = this.arg
7680
if (inputProps[attr] && attr in this.el) {
7781
if (!this.valueRemoved) {

test/unit/specs/compiler/compile_spec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,48 @@ if (_.inBrowser) {
469469
expect(el.innerHTML).toBe('<test test="1">{{a}}</test>')
470470
})
471471

472+
it('attribute interpolation', function (done) {
473+
var vm = new Vue({
474+
el: el,
475+
template: '<div id="{{a}}" class="b {{c}} d"></div>',
476+
data: {
477+
a: 'aaa',
478+
c: 'ccc'
479+
}
480+
})
481+
expect(el.innerHTML).toBe('<div id="aaa" class="b ccc d"></div>')
482+
vm.a = 'aa'
483+
vm.c = 'cc'
484+
_.nextTick(function () {
485+
expect(el.innerHTML).toBe('<div id="aa" class="b cc d"></div>')
486+
done()
487+
})
488+
})
489+
490+
it('attribute interpolation: special cases', function () {
491+
new Vue({
492+
el: el,
493+
template: '<label for="{{a}}" data-test="{{b}}"></label><form accept-charset="{{c}}"></form>',
494+
data: {
495+
a: 'aaa',
496+
b: 'bbb',
497+
c: 'UTF-8'
498+
}
499+
})
500+
expect(el.innerHTML).toBe('<label for="aaa" data-test="bbb"></label><form accept-charset="UTF-8"></form>')
501+
})
502+
503+
it('attribute interpolation: warn invalid', function () {
504+
new Vue({
505+
el: el,
506+
template: '<div hello="{{a}}"></div>',
507+
data: {
508+
a: '123'
509+
}
510+
})
511+
expect(el.innerHTML).toBe('<div></div>')
512+
expect(hasWarned(_, 'attribute interpolation is allowed only in valid native attributes')).toBe(true)
513+
})
514+
472515
})
473516
}

0 commit comments

Comments
 (0)