attr_spec.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var _ = require('../../../../src/util')
  2. var def = require('../../../../src/directives/attr')
  3. if (_.inBrowser) {
  4. describe('v-attr', function () {
  5. var el
  6. beforeEach(function () {
  7. el = document.createElement('div')
  8. })
  9. it('normal attr', function () {
  10. var dir = {
  11. el: el,
  12. arg: 'test'
  13. }
  14. _.extend(dir, def)
  15. dir.bind()
  16. dir.update('ok')
  17. expect(el.getAttribute('test')).toBe('ok')
  18. dir.update('again')
  19. expect(el.getAttribute('test')).toBe('again')
  20. dir.update(null)
  21. expect(el.hasAttribute('test')).toBe(false)
  22. dir.update(false)
  23. expect(el.hasAttribute('test')).toBe(false)
  24. dir.update(0)
  25. expect(el.getAttribute('test')).toBe('0')
  26. })
  27. it('xlink', function () {
  28. var xlinkNS = 'http://www.w3.org/1999/xlink'
  29. var dir = {
  30. el: el,
  31. arg: 'xlink:href'
  32. }
  33. _.extend(dir, def)
  34. dir.bind()
  35. dir.update('ok')
  36. expect(el.getAttributeNS(xlinkNS, 'href')).toBe('ok')
  37. dir.update('again')
  38. expect(el.getAttributeNS(xlinkNS, 'href')).toBe('again')
  39. dir.update(null)
  40. expect(el.hasAttributeNS(xlinkNS, 'test')).toBe(false)
  41. })
  42. })
  43. }