forked from DevExpress/testcafe
/
utils.ts
41 lines (29 loc) · 1.12 KB
/
utils.ts
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
import adapter from '..//adapter/index';
export function visible (el: Node): boolean {
if (adapter.isIframeElement(el))
return adapter.isIframeVisible(el);
if (!adapter.isDomElement(el) && !adapter.isTextNode(el))
return false;
if (adapter.isOptionElement(el) || adapter.getTagName(el as Element) === 'optgroup')
return adapter.isOptionElementVisible(el);
return adapter.isElementVisible(el);
}
export function isNodeCollection (obj: unknown): obj is HTMLCollection | NodeList {
return obj instanceof adapter.nativeMethods.HTMLCollection || obj instanceof adapter.nativeMethods.NodeList;
}
export function castToArray (list: HTMLCollection | NodeList): Node[] {
const length = list.length;
const result = [];
for (let i = 0; i < length; i++)
result.push(list[i]);
return result;
}
export function isArrayOfNodes (obj: unknown): obj is Node[] {
if (!adapter.nativeMethods.isArray(obj))
return false;
for (let i = 0; i < obj.length; i++) {
if (!(obj[i] instanceof adapter.nativeMethods.Node))
return false;
}
return true;
}