class_spec.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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')
  26. expect(el.className).toBe('haha what')
  27. dir.update()
  28. expect(el.className).toBe('haha')
  29. })
  30. it('object value', function () {
  31. el.className = 'hoho'
  32. var dir = _.extend({ el: el }, def)
  33. dir.update({
  34. a: true,
  35. b: false
  36. })
  37. expect(el.className).toBe('hoho a')
  38. dir.update({
  39. b: true
  40. })
  41. expect(el.className).toBe('hoho b')
  42. dir.update(null)
  43. expect(el.className).toBe('hoho')
  44. })
  45. })
  46. }