component_spec.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // custom element, not defined
  22. el = document.createElement('test')
  23. res = _.checkComponentAttr(el, mockOptions)
  24. expect(res).toBeUndefined()
  25. // custom element, defined
  26. el = document.createElement('foo')
  27. res = _.checkComponentAttr(el, mockOptions)
  28. expect(res.id).toBe('foo')
  29. // is on undefined custom element
  30. // should be preserved in case it is a native custom element usage
  31. el = document.createElement('test2')
  32. el.setAttribute('is', 'bar')
  33. res = _.checkComponentAttr(el, mockOptions)
  34. expect(res).toBeUndefined()
  35. })
  36. })