UNPKG

1.86 kBTypeScriptView Raw
1// Type definitions for expect-puppeteer 2.2
2// Project: https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer
3// Definitions by: Josh Goldberg <https://github.com/JoshuaKGoldberg>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.4
6
7/// <reference types="jest" />
8
9import { ElementHandle, Page } from "puppeteer";
10
11/**
12 * Interval at which pageFunctions may be executed.
13 */
14type ExpectPolling = number | "mutation" | "raf";
15
16/**
17 * Configures how to poll for an element.
18 */
19interface ExpectTimingActions {
20 /**
21 * An interval at which the pageFunction is executed. Defaults to "raf".
22 */
23 polling?: ExpectPolling;
24
25 /**
26 * Maximum time to wait for in milliseconds. Defaults to 500.
27 */
28 timeout?: number;
29}
30
31interface ExpectToClickOptions extends ExpectTimingActions {
32 /**
33 * A text or a RegExp to match in element textContent.
34 */
35 text?: string | RegExp;
36}
37
38interface ExpectPuppeteer {
39 toClick(selector: string, options?: ExpectToClickOptions): Promise<void>;
40 toDisplayDialog(block: () => Promise<void>): Promise<void>;
41 toFill(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
42 toMatchElement(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
43 toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
44 toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise<void>;
45}
46
47declare global {
48 namespace jest {
49 // tslint:disable-next-line no-empty-interface
50 interface Matchers<R> extends ExpectPuppeteer { }
51 }
52}
53
54declare function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer;
55export = expectPuppeteer;