forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalVue.spec.js
147 lines (138 loc) · 3.81 KB
/
localVue.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import Vue from 'vue'
import {
describeWithMountingMethods,
isRunningPhantomJS,
vueVersion
} from '~resources/utils'
import { createLocalVue } from '~vue/test-utils'
import { itSkipIf } from 'conditional-specs'
import Vuex from 'vuex'
describeWithMountingMethods('options.localVue', mountingMethod => {
itSkipIf(
isRunningPhantomJS,
'mounts component using passed localVue as base Vue',
() => {
const TestComponent = {
template: `<div>{{test}}</div>`
}
const localVue = createLocalVue()
localVue.prototype.test = 'some value'
const wrapper = mountingMethod(TestComponent, {
localVue: localVue
})
const HTML = mountingMethod.name === 'renderToString'
? wrapper
: wrapper.html()
expect(HTML).to.contain('some value')
}
)
itSkipIf(
vueVersion < 2.3,
'works correctly with extended children', () => {
const localVue = createLocalVue()
localVue.use(Vuex)
const store = new Vuex.Store({
state: { val: 2 }
})
const ChildComponent = Vue.extend({
template: '<span>{{val}}</span>',
computed: {
val () {
return this.$store.state.val
}
}
})
const TestComponent = {
template: '<div><child-component /></div>',
components: {
ChildComponent
}
}
const wrapper = mountingMethod(TestComponent, {
localVue,
store
})
const HTML =
mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
if (mountingMethod.name === 'shallowMount') {
expect(HTML).to.not.contain('2')
} else {
expect(HTML).to.contain('2')
}
})
itSkipIf(
vueVersion < 2.3,
'is applied to deeply extended components', () => {
const GrandChildComponent = Vue.extend(Vue.extend({
template: '<div>{{$route.params}}</div>'
}))
const ChildComponent = Vue.extend(Vue.extend(Vue.extend({
template: '<div><grand-child-component />{{$route.params}}</div>',
components: {
GrandChildComponent
}
})))
const TestComponent = Vue.extend(Vue.extend({
template: '<child-component />',
components: { ChildComponent }
}))
const localVue = createLocalVue()
localVue.prototype.$route = {}
mountingMethod(TestComponent, {
localVue
})
})
it('is applied to components that extend from other components', () => {
const localVue = createLocalVue()
localVue.prototype.$route = {}
const Extends = {
created () {
console.log(this.$route.params)
}
}
const TestComponent = {
extends: Extends
}
mountingMethod(TestComponent, {
localVue
})
})
itSkipIf(
vueVersion < 2.3,
'is applied to mixed extended components', () => {
const BaseGrandChildComponent = {
created () {
this.$route.params
}
}
const GrandChildComponent = {
created () {
this.$route.params
},
template: '<div/>',
extends: BaseGrandChildComponent
}
const ChildComponent = Vue.extend(({
template: '<div><grand-child-component />{{$route.params}}</div>',
components: {
GrandChildComponent
}
}))
const TestComponent = Vue.extend(Vue.extend({
template: '<div><child-component /></div>',
components: { ChildComponent }
}))
const localVue = createLocalVue()
localVue.prototype.$route = {}
mountingMethod(TestComponent, {
localVue
})
})
it('does not add created mixin to localVue', () => {
const localVue = createLocalVue()
mountingMethod({ render: () => {} }, {
localVue
})
expect(localVue.options.created).to.equal(undefined)
})
})