forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmount.js
36 lines (28 loc) · 1.04 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
// @flow
import './lib/warn-if-no-window'
import Vue from 'vue'
import VueWrapper from './wrappers/vue-wrapper'
import createInstance from './lib/create-instance'
import createElement from './lib/create-element'
import './lib/polyfills/matches-polyfill'
import './lib/polyfills/object-assign-polyfill'
import errorHandler from './lib/error-handler'
import { findAllVueComponentsFromVm } from './lib/find-vue-components'
Vue.config.productionTip = false
Vue.config.devtools = false
Vue.config.errorHandler = errorHandler
export default function mount (component: Component, options: Options = {}): VueWrapper {
// Remove cached constructor
delete component._Ctor
const vm = createInstance(component, options)
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)
}
return new VueWrapper(vm, { attachedToDocument: !!options.attachToDocument })
}