bind_spec.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.descriptor = {
  13. arg: 'test'
  14. }
  15. dir.update('ok')
  16. expect(el.getAttribute('test')).toBe('ok')
  17. dir.update('again')
  18. expect(el.getAttribute('test')).toBe('again')
  19. dir.update(null)
  20. expect(el.hasAttribute('test')).toBe(false)
  21. dir.update(false)
  22. expect(el.hasAttribute('test')).toBe(false)
  23. dir.update(0)
  24. expect(el.getAttribute('test')).toBe('0')
  25. })
  26. it('should set property for input value', function () {
  27. dir.el = document.createElement('input')
  28. dir.descriptor = {
  29. arg: 'value'
  30. }
  31. dir.update('what')
  32. expect(dir.el.hasAttribute('value')).toBe(false)
  33. expect(dir.el.value).toBe('what')
  34. dir.el = document.createElement('input')
  35. dir.el.type = 'checkbox'
  36. dir.descriptor = {
  37. arg: 'checked'
  38. }
  39. expect(dir.el.checked).toBe(false)
  40. dir.update(true)
  41. expect(dir.el.checked).toBe(true)
  42. })
  43. it('xlink', function () {
  44. var xlinkNS = 'http://www.w3.org/1999/xlink'
  45. dir.descriptor = {
  46. arg: 'xlink:special'
  47. }
  48. dir.update('ok')
  49. expect(el.getAttributeNS(xlinkNS, 'special')).toBe('ok')
  50. dir.update('again')
  51. expect(el.getAttributeNS(xlinkNS, 'special')).toBe('again')
  52. dir.update(null)
  53. expect(el.hasAttributeNS(xlinkNS, 'special')).toBe(false)
  54. })
  55. })
  56. }