forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalVue.spec.js
73 lines (71 loc) · 2 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
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')
}
})
})