class_spec.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. })
  48. }