-
Notifications
You must be signed in to change notification settings - Fork 672
/
mount.js
44 lines (37 loc) · 1.34 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
// @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'
Vue.config.productionTip = false
Vue.config.devtools = false
Vue.config.errorHandler = errorHandler
export default function mount (component: Component, options: Options = {}): VueWrapper {
warnIfNoWindow()
// Remove cached constructor
delete component._Ctor
const vueClass = options.localVue || createLocalVue()
const vm = createInstance(component, mergeOptions(options, config), vueClass)
if (options.attachToDocument) {
vm.$mount(createElement())
} else {
vm.$mount()
}
const componentsWithError = findAllVueComponentsFromVm(vm).filter(c => c._error)
if (componentsWithError.length > 0) {
throw (componentsWithError[0]._error)
}
const wrapperOptions = {
attachedToDocument: !!options.attachToDocument,
sync: !!((options.sync || options.sync === undefined))
}
return new VueWrapper(vm, wrapperOptions)
}