class_spec.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var _ = require('src/util')
  2. var def = require('src/directives/internal/class')
  3. describe(':class', function () {
  4. var el
  5. beforeEach(function () {
  6. el = document.createElement('div')
  7. })
  8. it('plain string', function () {
  9. el.className = 'haha'
  10. var dir = _.extend({ el: el }, def)
  11. dir.update('test')
  12. expect(el.className).toBe('haha test')
  13. dir.update('what now test')
  14. expect(el.className).toBe('haha test now what')
  15. dir.update('ok cool')
  16. expect(el.className).toBe('haha cool ok')
  17. dir.update()
  18. expect(el.className).toBe('haha')
  19. })
  20. it('object value', function () {
  21. el.className = 'hoho'
  22. var dir = _.extend({ el: el }, def)
  23. dir.update({
  24. a: true,
  25. b: false
  26. })
  27. expect(el.className).toBe('hoho a')
  28. dir.update({
  29. b: true
  30. })
  31. expect(el.className).toBe('hoho b')
  32. dir.update(null)
  33. expect(el.className).toBe('hoho')
  34. })
  35. it('array value', function () {
  36. el.className = 'a'
  37. var dir = _.extend({ el: el }, def)
  38. dir.update(['b', 'c'])
  39. expect(el.className).toBe('a b c')
  40. dir.update(['d', 'c'])
  41. expect(el.className).toBe('a c d')
  42. dir.update()
  43. expect(el.className).toBe('a')
  44. // test mutating array
  45. var arr = ['e', '']
  46. dir.update(arr)
  47. expect(el.className).toBe('a e')
  48. arr.length = 0
  49. arr.push('f')
  50. dir.update(arr)
  51. expect(el.className).toBe('a f')
  52. })
  53. })