Răsfoiți Sursa

unit test for bind- and on-

Evan You 10 ani în urmă
părinte
comite
d3068b3865

+ 2 - 0
src/directives/index.js

@@ -1,3 +1,5 @@
+// TODO: only expose core in 1.0.0
+
 // manipulation directives
 exports.text = require('./text')
 exports.html = require('./html')

+ 25 - 0
test/unit/specs/compiler/compile_spec.js

@@ -1,6 +1,7 @@
 var Vue = require('../../../../src/vue')
 var _ = require('../../../../src/util')
 var dirParser = require('../../../../src/parsers/directive')
+var newDirParser = require('../../../../src/parsers/directive-new')
 var compiler = require('../../../../src/compiler')
 var compile = compiler.compile
 
@@ -68,6 +69,30 @@ if (_.inBrowser) {
       expect(vm._bindDir.calls.argsFor(1)[0]).toBe('b')
     })
 
+    it('bind- syntax', function () {
+      el.setAttribute('bind-class', 'a')
+      el.setAttribute('bind-style', 'b')
+      el.setAttribute('bind-title', 'c')
+      var descA = newDirParser.parse('a')
+      var descB = newDirParser.parse('b')
+      var descC = newDirParser.parse('c')
+      var linker = compile(el, Vue.options)
+      linker(vm, el)
+      expect(vm._bindDir.calls.count()).toBe(3)
+      expect(vm._bindDir).toHaveBeenCalledWith('class', el, descA, Vue.options.directives.class, undefined, undefined, undefined)
+      expect(vm._bindDir).toHaveBeenCalledWith('style', el, descB, Vue.options.directives.style, undefined, undefined, undefined)
+      expect(vm._bindDir).toHaveBeenCalledWith('attr', el, descC, Vue.options.directives.attr, undefined, undefined, undefined)
+    })
+
+    it('on- syntax', function () {
+      el.setAttribute('on-click', 'a++')
+      var desc = newDirParser.parse('a++')
+      var linker = compile(el, Vue.options)
+      linker(vm, el)
+      expect(vm._bindDir.calls.count()).toBe(1)
+      expect(vm._bindDir).toHaveBeenCalledWith('on', el, desc, Vue.options.directives.on, undefined, undefined, undefined)
+    })
+
     it('text interpolation', function () {
       data.b = 'yeah'
       el.innerHTML = '{{a}} and {{*b}}'

+ 11 - 0
test/unit/specs/directives/class_spec.js

@@ -50,5 +50,16 @@ if (_.inBrowser) {
       expect(el.className).toBe('hoho')
     })
 
+    it('array value', function () {
+      el.className = 'a'
+      var dir = _.extend({ el: el }, def)
+      dir.update(['b', 'c'])
+      expect(el.className).toBe('a b c')
+      dir.update(['d', 'c'])
+      expect(el.className).toBe('a c d')
+      dir.update()
+      expect(el.className).toBe('a')
+    })
+
   })
 }