UNPKG

2.95 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 // These must all match the ExpectPuppeteer interface above.
40 // We can't extend from it directly because some method names conflict in type-incompatible ways.
41 toClick(selector: string, options?: ExpectToClickOptions): Promise<void>;
42 toDisplayDialog(block: () => Promise<void>): Promise<void>;
43 toFill(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
44 toMatch(selector: string, options?: ExpectTimingActions): Promise<void>;
45 toMatchElement(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
46 toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
47 toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise<void>;
48}
49
50declare global {
51 namespace jest {
52 // tslint:disable-next-line no-empty-interface
53 interface Matchers<R> {
54 // These must all match the ExpectPuppeteer interface above.
55 // We can't extend from it directly because some method names conflict in type-incompatible ways.
56 toClick(selector: string, options?: ExpectToClickOptions): Promise<void>;
57 toDisplayDialog(block: () => Promise<void>): Promise<void>;
58 toFill(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
59 toMatch(selector: string, options?: ExpectTimingActions): Promise<void>;
60 toMatchElement(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
61 toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
62 toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise<void>;
63 }
64 }
65}
66
67declare function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer;
68export = expectPuppeteer;