forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmount.js
58 lines (44 loc) · 1.35 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
// @flow
import Vue from 'vue'
import VueWrapper from './vue-wrapper'
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 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: Component,
options: Options = {}
): VueWrapper | Wrapper {
warnIfNoWindow()
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,
sync: mergedOptions.sync
}
const root = parentVm.$options._isFunctionalContainer
? vm._vnode
: vm.$children[0]
return createWrapper(root, wrapperOptions)
}