forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-selector.js
44 lines (40 loc) · 949 Bytes
/
get-selector.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
// @flow
import {
isDomSelector,
isNameSelector,
isRefSelector,
isVueComponent
} from 'shared/validators'
import { throwError } from 'shared/util'
import {
REF_SELECTOR,
COMPONENT_SELECTOR,
NAME_SELECTOR,
DOM_SELECTOR,
INVALID_SELECTOR
} from 'shared/consts'
function getSelectorType (
selector: Selector
): string {
if (isDomSelector(selector)) return DOM_SELECTOR
if (isVueComponent(selector)) return COMPONENT_SELECTOR
if (isNameSelector(selector)) return NAME_SELECTOR
if (isRefSelector(selector)) return REF_SELECTOR
return INVALID_SELECTOR
}
export default function getSelector (
selector: Selector,
methodName: string
): Object {
const type = getSelectorType(selector)
if (type === INVALID_SELECTOR) {
throwError(
`wrapper.${methodName}() must be passed a valid CSS selector, Vue ` +
`constructor, or valid find option object`
)
}
return {
type,
value: selector
}
}