Merge pull request #24729 from JoshuaKGoldberg/expect-puppeteer

Added expect-puppeteer types
This commit is contained in:
Paul van Brenk
2018-04-05 12:49:24 -07:00
committed by GitHub
4 changed files with 108 additions and 0 deletions
@@ -0,0 +1,29 @@
import { ElementHandle, Page } from "puppeteer";
const testGlobal = async (instance: ElementHandle | Page) => {
await expect(instance).toClick("selector");
await expect(instance).toClick("selector", { polling: "mutation", text: "text" });
await expect(instance).toClick("selector", { polling: "raf", timeout: 777 });
await expect(instance).toDisplayDialog(async () => {});
await expect(instance).toFill("selector", "value");
await expect(instance).toFill("selector", "value", { polling: 777 });
await expect(instance).toMatchElement("selector", "value");
await expect(instance).toMatchElement("selector", "value", { polling: "mutation" });
await expect(instance).toSelect("selector", "valueOrText");
await expect(instance).toSelect("selector", "valueOrText", { polling: "raf" });
await expect(instance).toUploadFile("selector", "filePath");
await expect(instance).toUploadFile("selector", "filePath", { timeout: 777 });
};
const testImported = async (instance: ElementHandle | Page) => {
const expectPuppeteer = await import("expect-puppeteer");
await expectPuppeteer(instance).toClick("selector");
await expect(instance).toClick("selector", { polling: "mutation", text: "text" });
await expect(instance).toClick("selector", { polling: "raf", timeout: 777 });
};
+55
View File
@@ -0,0 +1,55 @@
// Type definitions for expect-puppeteer 2.2
// Project: https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer
// Definitions by: Josh Goldberg <https://github.com/JoshuaKGoldberg>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="jest" />
import { ElementHandle, Page } from "puppeteer";
/**
* Interval at which pageFunctions may be executed.
*/
type ExpectPolling = number | "mutation" | "raf";
/**
* Configures how to poll for an element.
*/
interface ExpectTimingActions {
/**
* An interval at which the pageFunction is executed. Defaults to "raf".
*/
polling?: ExpectPolling;
/**
* Maximum time to wait for in milliseconds. Defaults to 500.
*/
timeout?: number;
}
interface ExpectToClickOptions extends ExpectTimingActions {
/**
* A text or a RegExp to match in element textContent.
*/
text?: string | RegExp;
}
interface ExpectPuppeteer {
toClick(selector: string, options?: ExpectToClickOptions): Promise<void>;
toDisplayDialog(block: () => Promise<void>): Promise<void>;
toFill(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
toMatchElement(selector: string, value: string, options?: ExpectTimingActions): Promise<void>;
toSelect(selector: string, valueOrText: string, options?: ExpectTimingActions): Promise<void>;
toUploadFile(selector: string, filePath: string, options?: ExpectTimingActions): Promise<void>;
}
declare global {
namespace jest {
// tslint:disable-next-line no-empty-interface
interface Matchers<R> extends ExpectPuppeteer { }
}
}
declare function expectPuppeteer(instance: ElementHandle | Page): ExpectPuppeteer;
export = expectPuppeteer;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"expect-puppeteer-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }