forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmount.js
47 lines (33 loc) · 1.25 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
import Vue from 'vue'
import createInstance from 'create-instance'
import createElement from './create-element'
import { throwIfInstancesThrew, addGlobalErrorHandler } from './error'
import { mergeOptions } from 'shared/merge-options'
import config from './config'
import warnIfNoWindow from './warn-if-no-window'
import polyfill from './polyfill'
import createWrapper from './create-wrapper'
import createLocalVue from './create-local-vue'
import { validateOptions } from 'shared/validate-options'
Vue.config.productionTip = false
Vue.config.devtools = false
export default function mount(component, options = {}) {
warnIfNoWindow()
polyfill()
addGlobalErrorHandler(Vue)
const _Vue = createLocalVue(options.localVue)
const mergedOptions = mergeOptions(options, config)
validateOptions(mergedOptions, component)
const parentVm = createInstance(component, mergedOptions, _Vue)
const el = options.attachToDocument ? createElement() : undefined
const vm = parentVm.$mount(el)
component._Ctor = {}
throwIfInstancesThrew(vm)
const wrapperOptions = {
attachedToDocument: !!mergedOptions.attachToDocument
}
const root = parentVm.$options._isFunctionalContainer
? vm._vnode
: vm.$children[0]
return createWrapper(root, wrapperOptions)
}