|
|
@@ -3,42 +3,41 @@ var _ = require('src/util')
|
|
|
describe('Util - component', function () {
|
|
|
it('checkComponentAttr', function () {
|
|
|
var el = document.createElement('component')
|
|
|
+ var mockOptions = { components: {
|
|
|
+ foo: {}
|
|
|
+ }}
|
|
|
|
|
|
// <component> with no is attr
|
|
|
- var res = _.checkComponentAttr(el)
|
|
|
+ var res = _.checkComponentAttr(el, mockOptions)
|
|
|
expect(res).toBeUndefined()
|
|
|
|
|
|
// static <component is="...">
|
|
|
el.setAttribute('is', 'foo')
|
|
|
- res = _.checkComponentAttr(el)
|
|
|
+ res = _.checkComponentAttr(el, mockOptions)
|
|
|
expect(res.id).toBe('foo')
|
|
|
expect(res.dynamic).toBeFalsy()
|
|
|
|
|
|
// <component :is="...">
|
|
|
el.setAttribute(':is', 'foo')
|
|
|
- res = _.checkComponentAttr(el)
|
|
|
+ res = _.checkComponentAttr(el, mockOptions)
|
|
|
expect(res.id).toBe('foo')
|
|
|
expect(res.dynamic).toBe(true)
|
|
|
|
|
|
// custom element, not defined
|
|
|
el = document.createElement('test')
|
|
|
- res = _.checkComponentAttr(el, {
|
|
|
- components: {}
|
|
|
- })
|
|
|
+ res = _.checkComponentAttr(el, mockOptions)
|
|
|
expect(res).toBeUndefined()
|
|
|
|
|
|
// custom element, defined
|
|
|
- res = _.checkComponentAttr(el, {
|
|
|
- components: { test: true }
|
|
|
- })
|
|
|
- expect(res.id).toBe('test')
|
|
|
+ el = document.createElement('foo')
|
|
|
+ res = _.checkComponentAttr(el, mockOptions)
|
|
|
+ expect(res.id).toBe('foo')
|
|
|
|
|
|
// is on undefined custom element
|
|
|
+ // should be preserved in case it is a native custom element usage
|
|
|
el = document.createElement('test2')
|
|
|
- el.setAttribute('is', 'foo')
|
|
|
- res = _.checkComponentAttr(el, {
|
|
|
- components: {}
|
|
|
- })
|
|
|
- expect(res.id).toBe('foo')
|
|
|
+ el.setAttribute('is', 'bar')
|
|
|
+ res = _.checkComponentAttr(el, mockOptions)
|
|
|
+ expect(res).toBeUndefined()
|
|
|
})
|
|
|
})
|