forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmount.js
73 lines (54 loc) · 1.8 KB
/
mount.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
// @flow
import './matches-polyfill'
import './object-assign-polyfill'
import Vue from 'vue'
import VueWrapper from './vue-wrapper'
import createInstance from 'create-instance'
import createElement from './create-element'
import createLocalVue from './create-local-vue'
import errorHandler from './error-handler'
import { findAllVueComponentsFromVm } from './find-vue-components'
import { mergeOptions } from 'shared/merge-options'
import config from './config'
import warnIfNoWindow from './warn-if-no-window'
import { addScopedSlots } from './add-scoped-slots'
Vue.config.productionTip = false
Vue.config.devtools = false
export default function mount (component: Component, options: Options = {}): VueWrapper {
const existingErrorHandler = Vue.config.errorHandler
Vue.config.errorHandler = errorHandler
warnIfNoWindow()
// Remove cached constructor
delete component._Ctor
const vueConstructor = options.localVue || createLocalVue()
const elm = options.attachToDocument
? createElement()
: undefined
const mergedOptions = mergeOptions(options, config)
const parentVm = createInstance(
component,
mergedOptions,
vueConstructor,
elm
)
const vm = parentVm.$mount(elm).$refs.vm
// Workaround for Vue < 2.5
vm._staticTrees = []
if (options.scopedSlots) {
addScopedSlots(vm, options.scopedSlots)
if (mergedOptions.sync) {
vm._watcher.sync = true
}
vm.$forceUpdate()
}
const componentsWithError = findAllVueComponentsFromVm(vm).filter(c => c._error)
if (componentsWithError.length > 0) {
throw (componentsWithError[0]._error)
}
Vue.config.errorHandler = existingErrorHandler
const wrapperOptions = {
attachedToDocument: !!mergedOptions.attachToDocument,
sync: mergedOptions.sync
}
return new VueWrapper(vm, wrapperOptions)
}