diff --git a/src/entries/web-runtime-with-compiler.js b/src/entries/web-runtime-with-compiler.js index af960ce3..37da5791 100644 --- a/src/entries/web-runtime-with-compiler.js +++ b/src/entries/web-runtime-with-compiler.js @@ -26,7 +26,10 @@ Vue.prototype.$mount = function (el: string | Element): Component { } else if (template.nodeType) { template = template.innerHTML } else { - warn('invalid template option:' + template, this) + if (process.env.NODE_ENV !== 'production') { + warn('invalid template option:' + template, this) + } + return this } } else if (el) { template = getOuterHTML(el) diff --git a/test/unit/features/options/template.spec.js b/test/unit/features/options/template.spec.js index e69de29b..8cfc61ff 100644 --- a/test/unit/features/options/template.spec.js +++ b/test/unit/features/options/template.spec.js @@ -0,0 +1,53 @@ +import Vue from 'vue' + +describe('Options template', () => { + let el + beforeEach(() => { + el = document.createElement('script') + el.type = 'x-template' + el.id = 'app' + el.innerHTML = '
{{message}}
' + document.body.appendChild(el) + }) + + afterEach(() => { + document.body.removeChild(el) + }) + + it('basic usage', () => { + const vm = new Vue({ + template: '{{message}}
' + const vm = new Vue({ + template: elm, + data: { message: 'hello world' } + }).$mount() + expect(vm.$el.tagName).toBe('P') + expect(vm.$el.textContent).toBe(vm.message) + }) + + it('invalid template', () => { + new Vue({ + template: Vue, + data: { message: 'hello world' } + }).$mount() + expect('invalid template option').toHaveBeenWarned() + }) +})