|
|
@@ -4,18 +4,16 @@ var def = require('../../../../src/directives/attr')
|
|
|
if (_.inBrowser) {
|
|
|
describe('v-attr', function () {
|
|
|
|
|
|
- var el
|
|
|
+ var el, dir
|
|
|
beforeEach(function () {
|
|
|
el = document.createElement('div')
|
|
|
+ dir = {el:el}
|
|
|
+ _.extend(dir, def)
|
|
|
})
|
|
|
|
|
|
it('normal attr', function () {
|
|
|
- var dir = {
|
|
|
- el: el,
|
|
|
- arg: 'test'
|
|
|
- }
|
|
|
- _.extend(dir, def)
|
|
|
- dir.bind()
|
|
|
+ dir.arg = 'test'
|
|
|
+
|
|
|
dir.update('ok')
|
|
|
expect(el.getAttribute('test')).toBe('ok')
|
|
|
dir.update('again')
|
|
|
@@ -30,19 +28,33 @@ if (_.inBrowser) {
|
|
|
|
|
|
it('xlink', function () {
|
|
|
var xlinkNS = 'http://www.w3.org/1999/xlink'
|
|
|
- var dir = {
|
|
|
- el: el,
|
|
|
- arg: 'xlink:href'
|
|
|
- }
|
|
|
- _.extend(dir, def)
|
|
|
- dir.bind()
|
|
|
+ dir.arg = 'xlink:special'
|
|
|
+
|
|
|
dir.update('ok')
|
|
|
- expect(el.getAttributeNS(xlinkNS, 'href')).toBe('ok')
|
|
|
+ expect(el.getAttributeNS(xlinkNS, 'special')).toBe('ok')
|
|
|
dir.update('again')
|
|
|
- expect(el.getAttributeNS(xlinkNS, 'href')).toBe('again')
|
|
|
+ expect(el.getAttributeNS(xlinkNS, 'special')).toBe('again')
|
|
|
dir.update(null)
|
|
|
- expect(el.hasAttributeNS(xlinkNS, 'test')).toBe(false)
|
|
|
+ expect(el.hasAttributeNS(xlinkNS, 'special')).toBe(false)
|
|
|
})
|
|
|
|
|
|
+ it('object and xlink', function () {
|
|
|
+ var xlinkNS = 'http://www.w3.org/1999/xlink'
|
|
|
+ var obj1 = {special:'ok', test:'again'}
|
|
|
+ var obj2 = {'xlink:href': '#', test: 'ok', empty:null}
|
|
|
+ dir.update(obj2)
|
|
|
+ expect(el.getAttributeNS(xlinkNS, 'href')).toBe('#')
|
|
|
+ expect(el.getAttribute('test')).toBe('ok')
|
|
|
+ expect(el.hasAttribute('empty')).toBe(false)
|
|
|
+ dir.update(obj1)
|
|
|
+ expect(el.hasAttributeNS(xlinkNS, 'href')).toBe(false)
|
|
|
+ expect(el.getAttribute('special')).toBe('ok')
|
|
|
+ expect(el.getAttribute('test')).toBe('again')
|
|
|
+ obj1.test = null
|
|
|
+ dir.update(obj1)
|
|
|
+ expect(el.hasAttribute('test')).toBe(false)
|
|
|
+ dir.update(obj2)
|
|
|
+ expect(el.getAttributeNS(xlinkNS, 'href')).toBe('#')
|
|
|
+ })
|
|
|
})
|
|
|
-}
|
|
|
+}
|