forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalVue.spec.js
95 lines (91 loc) · 2.54 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
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>
`,
data: { test: '' }
}
const localVue = Vue.extend()
localVue.version = '2.3'
const wrapper = mountingMethod(TestComponent, {
localVue: localVue,
mocks: { test: 'some value' }
})
const HTML =
mountingMethod.name === 'renderToString' ? wrapper : wrapper.html()
expect(HTML).to.contain('some value')
const freshWrapper = mountingMethod(TestComponent)
const freshHTML =
mountingMethod.name === 'renderToString'
? freshWrapper
: freshWrapper.html()
expect(freshHTML).to.not.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')
}
})
it('is applies to child extended components', () => {
const ChildComponent = Vue.extend({
template: '<div>{{$route.params}}</div>'
})
const TestComponent = Vue.extend({
template: '<child-component />',
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)
})
})