attr_spec.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. })
  23. it('xlink', function () {
  24. var xlinkNS = 'http://www.w3.org/1999/xlink'
  25. var dir = {
  26. el: el,
  27. arg: 'xlink:href'
  28. }
  29. _.extend(dir, def)
  30. dir.bind()
  31. dir.update('ok')
  32. expect(el.getAttributeNS(xlinkNS, 'href')).toBe('ok')
  33. dir.update('again')
  34. expect(el.getAttributeNS(xlinkNS, 'href')).toBe('again')
  35. dir.update(null)
  36. expect(el.hasAttributeNS(xlinkNS, 'test')).toBe(false)
  37. })
  38. })
  39. }