mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 21:17:55 +08:00
add options template tests (#2968)
* add options template tests ref: #2872 * fix runtime error and warning optimaize * update invalid template
This commit is contained in:
parent
c6d749b268
commit
05235942a7
@ -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)
|
||||
|
@ -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 = '<p>{{message}}</p>'
|
||||
document.body.appendChild(el)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(el)
|
||||
})
|
||||
|
||||
it('basic usage', () => {
|
||||
const vm = new Vue({
|
||||
template: '<div>{{message}}</div>',
|
||||
data: { message: 'hello world' }
|
||||
}).$mount()
|
||||
expect(vm.$el.tagName).toBe('DIV')
|
||||
expect(vm.$el.textContent).toBe(vm.message)
|
||||
})
|
||||
|
||||
it('id reference', () => {
|
||||
const vm = new Vue({
|
||||
template: '#app',
|
||||
data: { message: 'hello world' }
|
||||
}).$mount()
|
||||
expect(vm.$el.tagName).toBe('P')
|
||||
expect(vm.$el.textContent).toBe(vm.message)
|
||||
})
|
||||
|
||||
it('DOM element', () => {
|
||||
const elm = document.createElement('p')
|
||||
elm.innerHTML = '<p>{{message}}</p>'
|
||||
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()
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user