2
0

bind_spec.js 1.6 KB

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