component_spec.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var _ = require('src/util')
  2. describe('Util - component', function () {
  3. it('checkComponentAttr', function () {
  4. var el = document.createElement('component')
  5. var mockOptions = { components: {
  6. foo: {}
  7. }}
  8. // <component> with no is attr
  9. var res = _.checkComponentAttr(el, mockOptions)
  10. expect(res).toBeUndefined()
  11. // static <component is="...">
  12. el.setAttribute('is', 'foo')
  13. res = _.checkComponentAttr(el, mockOptions)
  14. expect(res.id).toBe('foo')
  15. expect(res.dynamic).toBeFalsy()
  16. // <component :is="...">
  17. el.setAttribute(':is', 'foo')
  18. res = _.checkComponentAttr(el, mockOptions)
  19. expect(res.id).toBe('foo')
  20. expect(res.dynamic).toBe(true)
  21. // <test is="...">
  22. el = document.createElement('test')
  23. el.setAttribute('is', 'foo')
  24. res = _.checkComponentAttr(el, mockOptions)
  25. expect(res.id).toBe('foo')
  26. expect(res.dynamic).toBeUndefined()
  27. // <test :is="...">
  28. el = document.createElement('test')
  29. el.setAttribute(':is', 'foo')
  30. res = _.checkComponentAttr(el, mockOptions)
  31. expect(res.id).toBe('foo')
  32. expect(res.dynamic).toBe(true)
  33. // custom element, not defined
  34. el = document.createElement('test')
  35. res = _.checkComponentAttr(el, mockOptions)
  36. expect(res).toBeUndefined()
  37. // custom element, defined
  38. el = document.createElement('foo')
  39. res = _.checkComponentAttr(el, mockOptions)
  40. expect(res.id).toBe('foo')
  41. // is on undefined custom element
  42. // should be preserved in case it is a native custom element usage
  43. el = document.createElement('test2')
  44. el.setAttribute('is', 'bar')
  45. res = _.checkComponentAttr(el, mockOptions)
  46. expect(res).toBeUndefined()
  47. })
  48. })