forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidators.js
76 lines (63 loc) · 1.76 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
65
66
67
68
69
70
71
72
73
74
75
76
// @flow
import {
throwError,
capitalize,
camelize,
hyphenate
} 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
}
export function templateContainsComponent (template: string, name: string) {
return [capitalize, camelize, hyphenate].some((format) => {
const re = new RegExp(`<${format(name)}\\s*(\\s|>|(\/>))`, 'g')
return re.test(template)
})
}