-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwait-for-the-element.d.ts
70 lines (66 loc) · 2.03 KB
/
wait-for-the-element.d.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
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
/**
* Options that define how elements should be searched for.
*/
export interface ElementSearchOptions
{
/**
* The maximum amount of time (in milliseconds) to wait.
*
* Defaults to `2500`.
*/
timeout? : number;
/**
* The root element to start searching from.
*
* Defaults to `document`.
*/
scope? : ParentNode;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
* Finds the first element matching a provided selector, if an element does not immediately match is will wait.
*
* Example usage:
*
* ``` js
* const element = await waitForTheElement('.target', {
* {
* timeout : 5000
* });
*
* if (element === null)
* {
* // After 5 seconds, a matching element still doesn't exist.
* }
* ```
*
* @param selector The selector that an element must match. This can be any selector that `document.querySelector()` supports.
* @param options The options that define how elements should be searched for.
*
* @typeParam E The type of the element you expect to be found.
*
* @returns A promise that will resolve with the first element matching the `selector`, or resolve with `null` if a matching element is not found.
*/
export function waitForTheElement<E extends Element> (selector : string, options? : ElementSearchOptions) : Promise<E | null>;
/**
* Waits for all elements to stop matching a provided selector.
*
* Example usage:
*
* ``` js
* const hidden = await waitForTheElementToDisappear('.target', {
* timeout : 5000
* });
*
* if (!hidden)
* {
* // After 5 seconds, a matching element still exists.
* }
* ```
*
* @param selector The selector that elements must not match. This can be any selector that `document.querySelector()` supports.
* @param options Options that define how elements should be searched for.
*
* @returns A promise that will resolve with `false` if elements are still found to be matching the `selector`, otherwise it will resolve with `true`.
*/
export function waitForTheElementToDisappear(selector : string, options? : ElementSearchOptions) : Promise<boolean>;