UNPKG

2.93 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// Tanguy Krotoff <https://github.com/tkrotoff>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 2.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 * Configures how to poll for an element.
19 */
20interface ExpectTimingActions {
21 /**
22 * An interval at which the pageFunction is executed. Defaults to "raf".
23 */
24 polling?: ExpectPolling;
25
26 /**
27 * Maximum time to wait for in milliseconds. Defaults to 500.
28 */
29 timeout?: number;
30}
31
32interface ExpectToClickOptions extends ExpectTimingActions {
33 /**
34 * A text or a RegExp to match in element textContent.
35 */
36 text?: string | RegExp;
37}
38
39interface ExpectPuppeteer {
40 // These must all match the ExpectPuppeteer interface above.
41 // We can't extend from it directly because some method names conflict in type-incompatible ways.
42 toClick(selector: string, options?: ExpectToClickOptions): Promise<void>;
43 toDisplayDialog(block: () => Promise<void>): Promise<Dialog>;
44 toFill(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
45 toMatch(selector: string, options?: ExpectTimingActions): Promise<void>;
46 toMatchElement(selector: string, options?: ExpectToClickOptions): Promise<void>;
47 toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
48 toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise<void>;
49}
50
51declare global {
52 namespace jest {
53 // tslint:disable-next-line no-empty-interface
54 interface Matchers<R> {
55 // These must all match the ExpectPuppeteer interface above.
56 // We can't extend from it directly because some method names conflict in type-incompatible ways.
57 toClick(selector: string, options?: ExpectToClickOptions): Promise<void>;
58 toDisplayDialog(block: () => Promise<void>): Promise<Dialog>;
59 toFill(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
60 toMatch(selector: string, options?: ExpectTimingActions): Promise<void>;
61 toMatchElement(selector: string, options?: ExpectToClickOptions): Promise<void>;
62 toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
63 toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise<void>;
64 }
65 }
66}
67
68declare function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer;
69export = expectPuppeteer;