1 |
|
2 |
|
3 | import { Dialog, ElementHandle, Page } from "puppeteer";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | type ExpectPolling = number | "mutation" | "raf";
|
9 |
|
10 | interface MatchSelector {
|
11 | |
12 |
|
13 |
|
14 | type: "css" | "xpath";
|
15 |
|
16 | |
17 |
|
18 |
|
19 | value: string;
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | interface ExpectDefaultOptions {
|
26 | |
27 |
|
28 |
|
29 | polling?: ExpectPolling | undefined;
|
30 |
|
31 | |
32 |
|
33 |
|
34 | timeout?: number | undefined;
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | interface ExpectTimingActions extends ExpectDefaultOptions {
|
41 | |
42 |
|
43 |
|
44 | delay?: number | undefined;
|
45 | }
|
46 |
|
47 | interface ExpectToClickOptions extends ExpectTimingActions {
|
48 | |
49 |
|
50 |
|
51 | button?: "left" | "right" | "middle" | undefined;
|
52 |
|
53 | |
54 |
|
55 |
|
56 | clickCount?: number | undefined;
|
57 |
|
58 | |
59 |
|
60 |
|
61 | delay?: number | undefined;
|
62 |
|
63 | |
64 |
|
65 |
|
66 | text?: string | RegExp | undefined;
|
67 |
|
68 | |
69 |
|
70 |
|
71 | visible?: boolean | undefined;
|
72 | }
|
73 |
|
74 | interface ExpectPuppeteer {
|
75 |
|
76 |
|
77 | toClick(selector: string | MatchSelector, options?: ExpectToClickOptions): Promise<void>;
|
78 | toDisplayDialog(block: () => Promise<void>): Promise<Dialog>;
|
79 | toFill(selector: string | MatchSelector, value: string, options?: ExpectTimingActions): Promise<void>;
|
80 | toFillForm(
|
81 | selector: string | MatchSelector,
|
82 | value: { [key: string]: any },
|
83 | options?: ExpectTimingActions,
|
84 | ): Promise<void>;
|
85 | toMatch(selector: string | MatchSelector, options?: ExpectTimingActions): Promise<void>;
|
86 | toMatchElement(selector: string | MatchSelector, options?: ExpectToClickOptions): Promise<void>;
|
87 | toSelect(selector: string | MatchSelector, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
|
88 | toUploadFile(selector: string | MatchSelector, filePath: string, options?: ExpectTimingActions): Promise<void>;
|
89 | }
|
90 |
|
91 | declare global {
|
92 | namespace jest {
|
93 | interface Matchers<R, T> {
|
94 |
|
95 |
|
96 | toClick(selector: string | MatchSelector, options?: ExpectToClickOptions): Promise<void>;
|
97 | toDisplayDialog(block: () => Promise<void>): Promise<Dialog>;
|
98 | toFill(selector: string | MatchSelector, value: string, options?: ExpectTimingActions): Promise<void>;
|
99 | toFillForm(
|
100 | selector: string | MatchSelector,
|
101 | value: { [key: string]: any },
|
102 | options?: ExpectTimingActions,
|
103 | ): Promise<void>;
|
104 | toMatch(matcher: string | RegExp, options?: ExpectTimingActions): Promise<void>;
|
105 | toMatchElement(selector: string | MatchSelector, options?: ExpectToClickOptions): Promise<ElementHandle>;
|
106 | toSelect(
|
107 | selector: string | MatchSelector,
|
108 | valueOrText: string,
|
109 | options?: ExpectTimingActions,
|
110 | ): Promise<void>;
|
111 | toUploadFile(
|
112 | selector: string | MatchSelector,
|
113 | filePath: string,
|
114 | options?: ExpectTimingActions,
|
115 | ): Promise<void>;
|
116 | }
|
117 | }
|
118 | }
|
119 |
|
120 | declare function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer;
|
121 |
|
122 | declare namespace expectPuppeteer {
|
123 | function setDefaultOptions(options: ExpectDefaultOptions): void;
|
124 | function getDefaultOptions(): ExpectDefaultOptions;
|
125 | }
|
126 |
|
127 | export = expectPuppeteer;
|