forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-options.js
61 lines (55 loc) · 1.73 KB
/
validate-options.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
import {
isPlainObject,
isFunctionalComponent,
isConstructor
} from './validators'
import { VUE_VERSION } from './consts'
import { compileTemplateForSlots } from './compile-template'
import { throwError } from './util'
import { validateSlots } from './validate-slots'
function vueExtendUnsupportedOption (option) {
return `options.${option} is not supported for ` +
`components created with Vue.extend in Vue < 2.3. ` +
`You can set ${option} to false to mount the component.`
}
// these options aren't supported if Vue is version < 2.3
// for components using Vue.extend. This is due to a bug
// that means the mixins we use to add properties are not applied
// correctly
const UNSUPPORTED_VERSION_OPTIONS = [
'mocks',
'stubs',
'localVue'
]
export function validateOptions (options, component) {
if (options.parentComponent && !isPlainObject(options.parentComponent)) {
throwError(
`options.parentComponent should be a valid Vue component options object`
)
}
if (!isFunctionalComponent(component) && options.context) {
throwError(
`mount.context can only be used when mounting a functional component`
)
}
if (options.context && !isPlainObject(options.context)) {
throwError('mount.context must be an object')
}
if (
VUE_VERSION < 2.3 && isConstructor(component)
) {
UNSUPPORTED_VERSION_OPTIONS.forEach((option) => {
if (options[option]) {
throwError(vueExtendUnsupportedOption(option))
}
})
}
if (options.slots) {
compileTemplateForSlots(options.slots)
// validate slots outside of the createSlots function so
// that we can throw an error without it being caught by
// the Vue error handler
// $FlowIgnore
validateSlots(options.slots)
}
}