class_spec.js 1.6 KB

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