소스 검색

fixing unit test for new syntax (wip)

Evan You 10 년 전
부모
커밋
7f7df413a4
3개의 변경된 파일27개의 추가작업 그리고 25개의 파일을 삭제
  1. 3 3
      src/compiler/compile.js
  2. 3 3
      test/unit/specs/async_component_spec.js
  3. 21 19
      test/unit/specs/compiler/compile_spec.js

+ 3 - 3
src/compiler/compile.js

@@ -579,9 +579,9 @@ function compileDirectives (attrs, options) {
     if (bindRE.test(name)) {
       dirName = name.replace(bindRE, '')
       if (dirName === 'style' || dirName === 'class') {
-        pushDir(dirName, internalDirectives[dirName])
+        pushDir(dirName, publicDirectives[dirName])
       } else {
-        pushDir('attr', internalDirectives.attr, {
+        pushDir('bind', publicDirectives.bind, {
           arg: dirName
         })
       }
@@ -590,7 +590,7 @@ function compileDirectives (attrs, options) {
     // normal directives
     if (name.indexOf('v-') === 0) {
       // check literal
-      isLiteral = literalRE.test(dirName)
+      isLiteral = literalRE.test(name)
       if (isLiteral) {
         name = name.replace(literalRE, '')
       }

+ 3 - 3
test/unit/specs/async_component_spec.js

@@ -38,7 +38,7 @@ describe('Async components', function () {
   it('dynamic', function (done) {
     var vm = new Vue({
       el: el,
-      template: '<component bind-is="view"></component>',
+      template: '<component :is="view"></component>',
       data: {
         view: 'view-a'
       },
@@ -82,7 +82,7 @@ describe('Async components', function () {
   it('invalidate pending on dynamic switch', function (done) {
     var vm = new Vue({
       el: el,
-      template: '<component bind-is="view"></component>',
+      template: '<component :is="view"></component>',
       data: {
         view: 'view-a'
       },
@@ -197,7 +197,7 @@ describe('Async components', function () {
   it('v-for', function (done) {
     new Vue({
       el: el,
-      template: '<test v-for="n in list" bind-n="n"></test>',
+      template: '<test v-for="n in list" :n="n"></test>',
       data: {
         list: [1, 2, 3]
       },

+ 21 - 19
test/unit/specs/compiler/compile_spec.js

@@ -2,6 +2,7 @@ var Vue = require('../../../../src/vue')
 var _ = require('../../../../src/util')
 var compiler = require('../../../../src/compiler')
 var compile = compiler.compile
+var publicDirectives = require('../../../../src/directives/public')
 var internalDirectives = require('../../../../src/directives/internal')
 
 if (_.inBrowser) {
@@ -102,10 +103,10 @@ if (_.inBrowser) {
       expect(directiveBind.calls.argsFor(3)[0]).toBe('a')
     })
 
-    it('bind- syntax', function () {
-      el.setAttribute('bind-class', 'a')
-      el.setAttribute('bind-style', 'b')
-      el.setAttribute('bind-title', 'c')
+    it('v-bind shorthand', function () {
+      el.setAttribute(':class', 'a')
+      el.setAttribute(':style', 'b')
+      el.setAttribute(':title', 'c')
       var linker = compile(el, Vue.options)
       linker(vm, el)
       expect(vm._bindDir.calls.count()).toBe(3)
@@ -113,25 +114,26 @@ if (_.inBrowser) {
       var args = vm._bindDir.calls.argsFor(0)
       expect(args[0].name).toBe('class')
       expect(args[0].expression).toBe('a')
-      expect(args[0].def).toBe(internalDirectives.class)
+      expect(args[0].def).toBe(publicDirectives.class)
       expect(args[1]).toBe(el)
       // 2
       args = vm._bindDir.calls.argsFor(1)
       expect(args[0].name).toBe('style')
       expect(args[0].expression).toBe('b')
-      expect(args[0].def).toBe(internalDirectives.style)
+      expect(args[0].def).toBe(publicDirectives.style)
       expect(args[1]).toBe(el)
       // 3
       args = vm._bindDir.calls.argsFor(2)
-      expect(args[0].name).toBe('attr')
+      expect(args[0].name).toBe('bind')
       expect(args[0].expression).toBe('c')
       expect(args[0].arg).toBe('title')
-      expect(args[0].def).toBe(internalDirectives.attr)
+      expect(args[0].def).toBe(publicDirectives.bind)
       expect(args[1]).toBe(el)
     })
 
-    it('on- syntax', function () {
-      el.setAttribute('on-click', 'a++')
+    it('v-on shorthand', function () {
+      el.innerHTML = '<div @click="a++"></div>'
+      el = el.firstChild
       var linker = compile(el, Vue.options)
       linker(vm, el)
       expect(vm._bindDir.calls.count()).toBe(1)
@@ -224,12 +226,12 @@ if (_.inBrowser) {
         { name: 'optimizeLiteral' }
       ]
       el.innerHTML = '<div ' +
-        'bind-test-normal="a" ' +
+        'v-bind:test-normal="a" ' +
         'test-literal="1" ' +
-        'bind-optimize-literal="1" ' +
-        'bind-test-two-way@="a" ' +
-        'bind-two-way-warn@="a + 1" ' +
-        'bind-test-one-time*="a"></div>'
+        ':optimize-literal="1" ' +
+        ':test-two-way@="a" ' +
+        ':two-way-warn@="a + 1" ' +
+        ':test-one-time*="a"></div>'
       compiler.compileAndLinkProps(vm, el.firstChild, props)
       expect(vm._bindDir.calls.count()).toBe(3) // skip literal and one time
       // literal
@@ -262,8 +264,8 @@ if (_.inBrowser) {
       // temporarily remove vm.$parent
       var context = vm._context
       vm._context = null
-      el.setAttribute('bind-a', '"hi"')
-      el.setAttribute('bind-b', 'hi')
+      el.setAttribute('v-bind:a', '"hi"')
+      el.setAttribute(':b', 'hi')
       compiler.compileAndLinkProps(vm, el, [
         { name: 'a' },
         { name: 'b' }
@@ -291,7 +293,7 @@ if (_.inBrowser) {
     })
 
     it('partial compilation', function () {
-      el.innerHTML = '<div bind-test="abc">{{bcd}}<p v-show="ok"></p></div>'
+      el.innerHTML = '<div v-bind:test="abc">{{bcd}}<p v-show="ok"></p></div>'
       var linker = compile(el, Vue.options, true)
       var decompile = linker(vm, el)
       expect(vm._directives.length).toBe(3)
@@ -338,7 +340,7 @@ if (_.inBrowser) {
     it('should teardown props and replacer directives when unlinking', function () {
       var vm = new Vue({
         el: el,
-        template: '<test bind-msg="msg"></test>',
+        template: '<test :msg="msg"></test>',
         data: {
           msg: 'hi'
         },