import Vue from 'vue' describe('Component', () => { it('static', () => { const vm = new Vue({ template: '', components: { test: { data () { return { a: 123 } }, template: '{{a}}' } } }).$mount() expect(vm.$el.tagName).toBe('SPAN') expect(vm.$el.innerHTML).toBe('123') }) it('using component in restricted elements', () => { const vm = new Vue({ template: '
', components: { test: { data () { return { a: 123 } }, template: '{{a}}' } } }).$mount() expect(vm.$el.innerHTML).toBe('
123
') }) it('"is" attribute', () => { const vm = new Vue({ template: '
', components: { test: { data () { return { a: 123 } }, template: '{{a}}' } } }).$mount() expect(vm.$el.innerHTML).toBe('
123
') }) it('inline-template', () => { const vm = new Vue({ template: '
{{a}}
', data: { a: 'parent' }, components: { test: { data () { return { a: 'child' } } } } }).$mount() expect(vm.$el.innerHTML).toBe('child') }) it('fragment instance warning', () => { new Vue({ template: '', components: { test: { data () { return { a: 123, b: 234 } }, template: '

{{a}}

{{b}}

' } } }).$mount() expect('Component template should contain exactly one root element').toHaveBeenWarned() }) it('dynamic', done => { const vm = new Vue({ template: '', data: { view: 'view-a' }, components: { 'view-a': { template: '
foo
', data () { return { view: 'a' } } }, 'view-b': { template: '
bar
', data () { return { view: 'b' } } } } }).$mount() expect(vm.$el.outerHTML).toBe('
foo
') vm.view = 'view-b' waitForUpdate(() => { expect(vm.$el.outerHTML).toBe('
bar
') vm.view = '' }) .then(() => { expect(vm.$el.nodeType).toBe(3) expect(vm.$el.data).toBe('') }).then(done) }) it(':is using raw component constructor', () => { const vm = new Vue({ template: '
' + '' + '' + '
', components: { test: { template: 'foo' }, async: function (resolve) { resolve({ template: 'bar' }) } } }).$mount() expect(vm.$el.innerHTML).toBe('foobar') }) it('dynamic combined with v-for', done => { const vm = new Vue({ template: '
' + '' + '
', data: { comps: [{ type: 'one' }, { type: 'two' }] }, components: { one: { template: 'one' }, two: { template: 'two' } } }).$mount() expect(vm.$el.innerHTML).toBe('onetwo') vm.comps[1].type = 'one' waitForUpdate(() => { expect(vm.$el.innerHTML).toBe('oneone') }).then(done) }) it('should compile parent template directives & content in parent scope', done => { const vm = new Vue({ data: { ok: false, message: 'hello' }, template: '{{message}}', components: { test: { template: '
{{message}}
', data () { return { message: 'world' } } } } }).$mount() expect(vm.$el.style.display).toBe('none') expect(vm.$el.textContent).toBe('hello world') vm.ok = true vm.message = 'bye' waitForUpdate(() => { expect(vm.$el.style.display).toBe('') expect(vm.$el.textContent).toBe('bye world') }).then(done) }) it('parent content + v-if', done => { const vm = new Vue({ data: { ok: false, message: 'hello' }, template: '{{message}}', components: { test: { template: '
{{message}}
', data () { return { message: 'world' } } } } }).$mount() expect(vm.$el.textContent).toBe('') expect(vm.$children.length).toBe(0) vm.ok = true waitForUpdate(() => { expect(vm.$children.length).toBe(1) expect(vm.$el.textContent).toBe('hello world') }).then(done) }) it('props', () => { const vm = new Vue({ data: { list: [{ a: 1 }, { a: 2 }] }, template: '', components: { test: { template: '', props: ['collection'] } } }).$mount() expect(vm.$el.outerHTML).toBe('') }) it('not found component should not throw', () => { expect(function () { new Vue({ template: '
' }) }).not.toThrow() }) })