Skip to content

Commit 7f7df41

Browse files
committed
fixing unit test for new syntax (wip)
1 parent cb36567 commit 7f7df41

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

src/compiler/compile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ function compileDirectives (attrs, options) {
579579
if (bindRE.test(name)) {
580580
dirName = name.replace(bindRE, '')
581581
if (dirName === 'style' || dirName === 'class') {
582-
pushDir(dirName, internalDirectives[dirName])
582+
pushDir(dirName, publicDirectives[dirName])
583583
} else {
584-
pushDir('attr', internalDirectives.attr, {
584+
pushDir('bind', publicDirectives.bind, {
585585
arg: dirName
586586
})
587587
}
@@ -590,7 +590,7 @@ function compileDirectives (attrs, options) {
590590
// normal directives
591591
if (name.indexOf('v-') === 0) {
592592
// check literal
593-
isLiteral = literalRE.test(dirName)
593+
isLiteral = literalRE.test(name)
594594
if (isLiteral) {
595595
name = name.replace(literalRE, '')
596596
}

test/unit/specs/async_component_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Async components', function () {
3838
it('dynamic', function (done) {
3939
var vm = new Vue({
4040
el: el,
41-
template: '<component bind-is="view"></component>',
41+
template: '<component :is="view"></component>',
4242
data: {
4343
view: 'view-a'
4444
},
@@ -82,7 +82,7 @@ describe('Async components', function () {
8282
it('invalidate pending on dynamic switch', function (done) {
8383
var vm = new Vue({
8484
el: el,
85-
template: '<component bind-is="view"></component>',
85+
template: '<component :is="view"></component>',
8686
data: {
8787
view: 'view-a'
8888
},
@@ -197,7 +197,7 @@ describe('Async components', function () {
197197
it('v-for', function (done) {
198198
new Vue({
199199
el: el,
200-
template: '<test v-for="n in list" bind-n="n"></test>',
200+
template: '<test v-for="n in list" :n="n"></test>',
201201
data: {
202202
list: [1, 2, 3]
203203
},

test/unit/specs/compiler/compile_spec.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var Vue = require('../../../../src/vue')
22
var _ = require('../../../../src/util')
33
var compiler = require('../../../../src/compiler')
44
var compile = compiler.compile
5+
var publicDirectives = require('../../../../src/directives/public')
56
var internalDirectives = require('../../../../src/directives/internal')
67

78
if (_.inBrowser) {
@@ -102,36 +103,37 @@ if (_.inBrowser) {
102103
expect(directiveBind.calls.argsFor(3)[0]).toBe('a')
103104
})
104105

105-
it('bind- syntax', function () {
106-
el.setAttribute('bind-class', 'a')
107-
el.setAttribute('bind-style', 'b')
108-
el.setAttribute('bind-title', 'c')
106+
it('v-bind shorthand', function () {
107+
el.setAttribute(':class', 'a')
108+
el.setAttribute(':style', 'b')
109+
el.setAttribute(':title', 'c')
109110
var linker = compile(el, Vue.options)
110111
linker(vm, el)
111112
expect(vm._bindDir.calls.count()).toBe(3)
112113
// 1
113114
var args = vm._bindDir.calls.argsFor(0)
114115
expect(args[0].name).toBe('class')
115116
expect(args[0].expression).toBe('a')
116-
expect(args[0].def).toBe(internalDirectives.class)
117+
expect(args[0].def).toBe(publicDirectives.class)
117118
expect(args[1]).toBe(el)
118119
// 2
119120
args = vm._bindDir.calls.argsFor(1)
120121
expect(args[0].name).toBe('style')
121122
expect(args[0].expression).toBe('b')
122-
expect(args[0].def).toBe(internalDirectives.style)
123+
expect(args[0].def).toBe(publicDirectives.style)
123124
expect(args[1]).toBe(el)
124125
// 3
125126
args = vm._bindDir.calls.argsFor(2)
126-
expect(args[0].name).toBe('attr')
127+
expect(args[0].name).toBe('bind')
127128
expect(args[0].expression).toBe('c')
128129
expect(args[0].arg).toBe('title')
129-
expect(args[0].def).toBe(internalDirectives.attr)
130+
expect(args[0].def).toBe(publicDirectives.bind)
130131
expect(args[1]).toBe(el)
131132
})
132133

133-
it('on- syntax', function () {
134-
el.setAttribute('on-click', 'a++')
134+
it('v-on shorthand', function () {
135+
el.innerHTML = '<div @click="a++"></div>'
136+
el = el.firstChild
135137
var linker = compile(el, Vue.options)
136138
linker(vm, el)
137139
expect(vm._bindDir.calls.count()).toBe(1)
@@ -224,12 +226,12 @@ if (_.inBrowser) {
224226
{ name: 'optimizeLiteral' }
225227
]
226228
el.innerHTML = '<div ' +
227-
'bind-test-normal="a" ' +
229+
'v-bind:test-normal="a" ' +
228230
'test-literal="1" ' +
229-
'bind-optimize-literal="1" ' +
230-
'bind-test-two-way@="a" ' +
231-
'bind-two-way-warn@="a + 1" ' +
232-
'bind-test-one-time*="a"></div>'
231+
':optimize-literal="1" ' +
232+
':test-two-way@="a" ' +
233+
':two-way-warn@="a + 1" ' +
234+
':test-one-time*="a"></div>'
233235
compiler.compileAndLinkProps(vm, el.firstChild, props)
234236
expect(vm._bindDir.calls.count()).toBe(3) // skip literal and one time
235237
// literal
@@ -262,8 +264,8 @@ if (_.inBrowser) {
262264
// temporarily remove vm.$parent
263265
var context = vm._context
264266
vm._context = null
265-
el.setAttribute('bind-a', '"hi"')
266-
el.setAttribute('bind-b', 'hi')
267+
el.setAttribute('v-bind:a', '"hi"')
268+
el.setAttribute(':b', 'hi')
267269
compiler.compileAndLinkProps(vm, el, [
268270
{ name: 'a' },
269271
{ name: 'b' }
@@ -291,7 +293,7 @@ if (_.inBrowser) {
291293
})
292294

293295
it('partial compilation', function () {
294-
el.innerHTML = '<div bind-test="abc">{{bcd}}<p v-show="ok"></p></div>'
296+
el.innerHTML = '<div v-bind:test="abc">{{bcd}}<p v-show="ok"></p></div>'
295297
var linker = compile(el, Vue.options, true)
296298
var decompile = linker(vm, el)
297299
expect(vm._directives.length).toBe(3)
@@ -338,7 +340,7 @@ if (_.inBrowser) {
338340
it('should teardown props and replacer directives when unlinking', function () {
339341
var vm = new Vue({
340342
el: el,
341-
template: '<test bind-msg="msg"></test>',
343+
template: '<test :msg="msg"></test>',
342344
data: {
343345
msg: 'hi'
344346
},

0 commit comments

Comments
 (0)