forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidators.js
97 lines (81 loc) · 2.21 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// @flow
import { throwError, capitalize, camelize, hyphenate } from './util'
export function isDomSelector (selector: any): boolean {
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): boolean {
if (typeof component === 'function' && component.options) {
return true
}
if (component === null || typeof component !== 'object') {
return false
}
if (component.extends || component._Ctor) {
return true
}
if (typeof component.template === 'string') {
return true
}
return typeof component.render === 'function'
}
export function componentNeedsCompiling (component: Component): boolean {
return (
component &&
!component.render &&
(component.template || component.extends || component.extendOptions) &&
!component.functional
)
}
export function isRefSelector (refOptionsObject: any): boolean {
if (
typeof refOptionsObject !== 'object' ||
Object.keys(refOptionsObject || {}).length !== 1
) {
return false
}
return typeof refOptionsObject.ref === 'string'
}
export function isNameSelector (nameOptionsObject: any): boolean {
if (typeof nameOptionsObject !== 'object' || nameOptionsObject === null) {
return false
}
return !!nameOptionsObject.name
}
export function templateContainsComponent (
template: string,
name: string
): boolean {
return [capitalize, camelize, hyphenate].some(format => {
const re = new RegExp(`<${format(name)}\\s*(\\s|>|(\/>))`, 'g')
return re.test(template)
})
}
export function isPlainObject (obj: any): boolean {
return Object.prototype.toString.call(obj) === '[object Object]'
}
export function isRequiredComponent (name: string): boolean {
return (
name === 'KeepAlive' || name === 'Transition' || name === 'TransitionGroup'
)
}