UNPKG

3.98 kBTypeScriptView Raw
1// Type definitions for expect-puppeteer 4.4
2// Project: https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer
3// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
4// Jason Mong <https://github.com/jfm710>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 3.8
7
8/// <reference types="jest" />
9
10import { ElementHandle, Page, Dialog } from "puppeteer";
11
12/**
13 * Interval at which pageFunctions may be executed.
14 */
15type ExpectPolling = number | "mutation" | "raf";
16
17/**
18 * Default options that apply to all expectations and can be set globally
19 */
20interface ExpectDefaultOptions {
21 /**
22 * An interval at which the pageFunction is executed. Defaults to "raf".
23 */
24 polling?: ExpectPolling | undefined;
25
26 /**
27 * Maximum time to wait for in milliseconds. Defaults to 500.
28 */
29 timeout?: number | undefined;
30}
31
32/**
33 * Configures how to poll for an element.
34 */
35interface ExpectTimingActions extends ExpectDefaultOptions {
36 /**
37 * delay to pass to the puppeteer element.type API
38 */
39 delay?: number | undefined;
40}
41
42interface ExpectToClickOptions extends ExpectTimingActions {
43 /**
44 * Defaults to left.
45 */
46 button?: "left" | "right" | "middle" | undefined;
47
48 /**
49 * defaults to 1. See UIEvent.detail.
50 */
51 clickCount?: number | undefined;
52
53 /**
54 * Time to wait between mousedown and mouseup in milliseconds. Defaults to 0.
55 */
56 delay?: number | undefined;
57
58 /**
59 * A text or a RegExp to match in element textContent.
60 */
61 text?: string | RegExp | undefined;
62
63 /**
64 * wait for element to be present in DOM and to be visible, i.e. to not have display: none or visibility: hidden CSS properties. Defaults to false.
65 */
66 visible?: boolean | undefined;
67}
68
69interface ExpectPuppeteer {
70 // These must all match the ExpectPuppeteer interface above.
71 // We can't extend from it directly because some method names conflict in type-incompatible ways.
72 toClick(selector: string, options?: ExpectToClickOptions): Promise<void>;
73 toDisplayDialog(block: () => Promise<void>): Promise<Dialog>;
74 toFill(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
75 toMatch(selector: string, options?: ExpectTimingActions): Promise<void>;
76 toMatchElement(selector: string, options?: ExpectToClickOptions): Promise<void>;
77 toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
78 toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise<void>;
79}
80
81declare global {
82 namespace jest {
83 interface Matchers<R, T> {
84 // These must all match the ExpectPuppeteer interface above.
85 // We can't extend from it directly because some method names conflict in type-incompatible ways.
86 toClick(selector: string, options?: ExpectToClickOptions): Promise<void>;
87 toDisplayDialog(block: () => Promise<void>): Promise<Dialog>;
88 toFill(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
89 toFillForm(selector: string, value: { [key: string]: any}, options?: ExpectTimingActions): Promise<void>;
90 toMatch(matcher: string | RegExp, options?: ExpectTimingActions): Promise<void>;
91 toMatchElement(selector: string, options?: ExpectToClickOptions): Promise<ElementHandle>;
92 toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
93 toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise<void>;
94 }
95 }
96}
97
98declare function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer;
99
100declare namespace expectPuppeteer {
101 function setDefaultOptions(options: ExpectDefaultOptions): void;
102 function getDefaultOptions(): ExpectDefaultOptions;
103}
104
105export = expectPuppeteer;