Merge pull request #32542 from whtsky/user-event

Add definitions for user-event
This commit is contained in:
Pranav Senthilnathan
2019-01-29 15:35:31 -08:00
committed by GitHub
4 changed files with 48 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
// Type definitions for user-event 1.4
// Project: https://github.com/Gpx/user-event#readme
// Definitions by: Wu Haotian <https://github.com/whtsky>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface UserOpts {
allAtOnce?: boolean;
delay?: number;
}
declare const userEvent: {
click: (element: Element | Window) => void;
dblClick: (element: Element | Window) => void;
type: (
element: Element | Window,
text: string,
userOpts?: UserOpts
) => Promise<void>;
};
export default userEvent;
+16
View File
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["dom", "es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "user-event-tests.ts"]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+11
View File
@@ -0,0 +1,11 @@
import userEvent, { UserOpts } from "user-event";
userEvent.click(document.body); // $ExpectType void
userEvent.dblClick(window); // $ExpectType void
userEvent.type(document.body, "s"); // $ExpectType Promise<void>
userEvent.type(document.body, "s", {}); // $ExpectType Promise<void>
userEvent.type(document.body, "s", { delay: 5000 }); // $ExpectType Promise<void>
userEvent.type(document.body, "s", { allAtOnce: true }); // $ExpectType Promise<void>
userEvent.type(document.body, "s", { delay: 1000, allAtOnce: false }); // $ExpectType Promise<void>
const u: UserOpts = { delay: 20 };