-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
/
Copy pathcomponents.spec.js
101 lines (92 loc) · 2.55 KB
/
components.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Vue from 'vue'
import { UA } from 'core/util/env'
import testObjectOption from '../../../helpers/test-object-option'
describe('Options components', () => {
testObjectOption('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 component names translated into 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()
})
// the HTMLUnknownElement check doesn't work in Android 4.2
// but since it doesn't support custom elements nor will any dev use it
// as their primary debugging browser, it doesn't really matter.
if (!(UA && /android 4\.2/.test(UA))) {
it('warn non-existent', () => {
new Vue({
template: '<test></test>'
}).$mount()
expect('Unknown custom element: <test>').toHaveBeenWarned()
})
}
})