forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidators.js
64 lines (52 loc) · 1.48 KB
/
validators.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
62
63
64
// @flow
import { throwError } from './util'
export function isDomSelector (selector: any) {
if (typeof selector !== 'string') {
return false
}
try {
if (typeof document === 'undefined') {
throwError('mount must be run in a browser environment like PhantomJS, jsdom or chrome')
}
} catch (error) {
throwError('mount must be run in a browser environment like PhantomJS, jsdom or chrome')
}
try {
document.querySelector(selector)
return true
} catch (error) {
return false
}
}
export function isVueComponent (component: any) {
if (typeof component === 'function' && component.options) {
return true
}
if (component === null || typeof component !== 'object') {
return false
}
if (component.extends || component._Ctor) {
return true
}
return typeof component.render === 'function'
}
export function componentNeedsCompiling (component: Component) {
return component &&
!component.render &&
(component.template ||
component.extends ||
component.extendOptions) &&
!component.functional
}
export function isRefSelector (refOptionsObject: any) {
if (typeof refOptionsObject !== 'object' || Object.keys(refOptionsObject || {}).length !== 1) {
return false
}
return typeof refOptionsObject.ref === 'string'
}
export function isNameSelector (nameOptionsObject: any) {
if (typeof nameOptionsObject !== 'object' || nameOptionsObject === null) {
return false
}
return !!nameOptionsObject.name
}