mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 13:07:40 +08:00
component option tests
This commit is contained in:
parent
0450aba1f1
commit
1e90fd6a52
76
test/unit/features/options/components.spec.js
Normal file
76
test/unit/features/options/components.spec.js
Normal file
@ -0,0 +1,76 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
describe('Options components', () => {
|
||||
it('should accept plain object', () => {
|
||||
const vm = new Vue({
|
||||
template: '<test></test>',
|
||||
components: {
|
||||
test: {
|
||||
template: '<div>hi</div>'
|
||||
}
|
||||
}
|
||||
}).$mount()
|
||||
expect(vm.$el.tagName).toBe('DIV')
|
||||
expect(vm.$el.textContent).toBe('hi')
|
||||
})
|
||||
|
||||
it('should accept extended constructor', () => {
|
||||
const Test = Vue.extend({
|
||||
template: '<div>hi</div>'
|
||||
})
|
||||
const vm = new Vue({
|
||||
template: '<test></test>',
|
||||
components: {
|
||||
test: Test
|
||||
}
|
||||
}).$mount()
|
||||
expect(vm.$el.tagName).toBe('DIV')
|
||||
expect(vm.$el.textContent).toBe('hi')
|
||||
})
|
||||
|
||||
it('should accept camelCase', () => {
|
||||
const myComp = {
|
||||
template: '<div>hi</div>'
|
||||
}
|
||||
const vm = new Vue({
|
||||
template: '<my-comp></my-comp>',
|
||||
components: {
|
||||
myComp
|
||||
}
|
||||
}).$mount()
|
||||
expect(vm.$el.tagName).toBe('DIV')
|
||||
expect(vm.$el.textContent).toBe('hi')
|
||||
})
|
||||
|
||||
it('should accept PascalCase', () => {
|
||||
const MyComp = {
|
||||
template: '<div>hi</div>'
|
||||
}
|
||||
const vm = new Vue({
|
||||
template: '<my-comp></my-comp>',
|
||||
components: {
|
||||
MyComp
|
||||
}
|
||||
}).$mount()
|
||||
expect(vm.$el.tagName).toBe('DIV')
|
||||
expect(vm.$el.textContent).toBe('hi')
|
||||
})
|
||||
|
||||
it('should warn native HTML elements', () => {
|
||||
new Vue({
|
||||
components: {
|
||||
div: { template: '<div></div>' }
|
||||
}
|
||||
})
|
||||
expect('Do not use built-in or reserved HTML elements as component').toHaveBeenWarned()
|
||||
})
|
||||
|
||||
it('should warn built-in elements', () => {
|
||||
new Vue({
|
||||
components: {
|
||||
component: { template: '<div></div>' }
|
||||
}
|
||||
})
|
||||
expect('Do not use built-in or reserved HTML elements as component').toHaveBeenWarned()
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user