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