forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmount.js
61 lines (49 loc) · 1.57 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
// @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 errorHandler from './error-handler'
import { findAllInstances } from './find'
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'
Vue.config.productionTip = false
Vue.config.devtools = false
export default function mount (
component: Component,
options: Options = {}
): VueWrapper | Wrapper {
const existingErrorHandler = Vue.config.errorHandler
Vue.config.errorHandler = errorHandler
warnIfNoWindow()
// Remove cached constructor
delete component._Ctor
const elm = options.attachToDocument ? createElement() : undefined
const mergedOptions = mergeOptions(options, config)
const parentVm = createInstance(
component,
mergedOptions,
createLocalVue(options.localVue)
)
const vm = parentVm.$mount(elm).$refs.vm
const componentsWithError = findAllInstances(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
}
const root = vm.$options._isFunctionalContainer
? vm._vnode
: vm
return createWrapper(root, wrapperOptions)
}