// Type definitions for expect-puppeteer 4.4 // Project: https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer // Definitions by: Tanguy Krotoff // Jason Mong // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.8 /// import { ElementHandle, Page, Dialog } from "puppeteer"; /** * Interval at which pageFunctions may be executed. */ type ExpectPolling = number | "mutation" | "raf"; /** * Default options that apply to all expectations and can be set globally */ interface ExpectDefaultOptions { /** * An interval at which the pageFunction is executed. Defaults to "raf". */ polling?: ExpectPolling | undefined; /** * Maximum time to wait for in milliseconds. Defaults to 500. */ timeout?: number | undefined; } /** * Configures how to poll for an element. */ interface ExpectTimingActions extends ExpectDefaultOptions { /** * delay to pass to the puppeteer element.type API */ delay?: number | undefined; } interface ExpectToClickOptions extends ExpectTimingActions { /** * Defaults to left. */ button?: "left" | "right" | "middle" | undefined; /** * defaults to 1. See UIEvent.detail. */ clickCount?: number | undefined; /** * Time to wait between mousedown and mouseup in milliseconds. Defaults to 0. */ delay?: number | undefined; /** * A text or a RegExp to match in element textContent. */ text?: string | RegExp | undefined; /** * 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. */ visible?: boolean | undefined; } interface ExpectPuppeteer { // These must all match the ExpectPuppeteer interface above. // We can't extend from it directly because some method names conflict in type-incompatible ways. toClick(selector: string, options?: ExpectToClickOptions): Promise; toDisplayDialog(block: () => Promise): Promise; toFill(selector: string, value: string, options?: ExpectTimingActions): Promise; toMatch(selector: string, options?: ExpectTimingActions): Promise; toMatchElement(selector: string, options?: ExpectToClickOptions): Promise; toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise; toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise; } declare global { namespace jest { interface Matchers { // These must all match the ExpectPuppeteer interface above. // We can't extend from it directly because some method names conflict in type-incompatible ways. toClick(selector: string, options?: ExpectToClickOptions): Promise; toDisplayDialog(block: () => Promise): Promise; toFill(selector: string, value: string, options?: ExpectTimingActions): Promise; toFillForm(selector: string, value: { [key: string]: any}, options?: ExpectTimingActions): Promise; toMatch(matcher: string | RegExp, options?: ExpectTimingActions): Promise; toMatchElement(selector: string, options?: ExpectToClickOptions): Promise; toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise; toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise; } } } declare function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer; declare namespace expectPuppeteer { function setDefaultOptions(options: ExpectDefaultOptions): void; function getDefaultOptions(): ExpectDefaultOptions; } export = expectPuppeteer;