forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshallow-mount.js
45 lines (39 loc) · 1.28 KB
/
shallow-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
// @flow
import './warn-if-no-window'
import Vue from 'vue'
import mount from './mount'
import type VueWrapper from './vue-wrapper'
import {
createComponentStubsForAll,
createComponentStubsForGlobals,
createBlankStub
} from 'shared/stub-components'
import { camelize, capitalize, hyphenate } from 'shared/util'
import { normalizeStubs } from 'shared/normalize'
export default function shallowMount (
component: Component,
options: Options = {}
): VueWrapper {
const _Vue = options.localVue || Vue
// remove any recursive components added to the constructor
// in vm._init from previous tests
if (component.name && component.components) {
delete component.components[capitalize(camelize(component.name))]
delete component.components[hyphenate(component.name)]
}
options.stubs = normalizeStubs(options.stubs)
// In Vue.extends, Vue adds a recursive component to the options
// This stub will override the component added by Vue
// $FlowIgnore
if (options.stubs && !options.stubs[component.name]) {
// $FlowIgnore
options.stubs[component.name] = createBlankStub(component, component.name)
}
return mount(component, {
...options,
components: {
...createComponentStubsForGlobals(_Vue),
...createComponentStubsForAll(component)
}
})
}