Skip to content

Commit 4b88e01

Browse files
Kimahrimanamcasey
authored andcommitted
Copied user-event definition to new testing-library organization (DefinitelyTyped#36000)
1 parent 695e81c commit 4b88e01

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Type definitions for @testing-library/user-event 4.0
2+
// Project: https://github.com/testing-library/user-event
3+
// Definitions by: Wu Haotian <https://github.com/whtsky>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
export interface UserOpts {
7+
allAtOnce?: boolean;
8+
delay?: number;
9+
}
10+
declare const userEvent: {
11+
click: (element: Element | Window) => void;
12+
dblClick: (element: Element | Window) => void;
13+
type: (
14+
element: Element | Window,
15+
text: string,
16+
userOpts?: UserOpts
17+
) => Promise<void>;
18+
};
19+
20+
export default userEvent;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import userEvent, { UserOpts } from "user-event";
2+
3+
userEvent.click(document.body); // $ExpectType void
4+
userEvent.dblClick(window); // $ExpectType void
5+
userEvent.type(document.body, "s"); // $ExpectType Promise<void>
6+
userEvent.type(document.body, "s", {}); // $ExpectType Promise<void>
7+
userEvent.type(document.body, "s", { delay: 5000 }); // $ExpectType Promise<void>
8+
userEvent.type(document.body, "s", { allAtOnce: true }); // $ExpectType Promise<void>
9+
userEvent.type(document.body, "s", { delay: 1000, allAtOnce: false }); // $ExpectType Promise<void>
10+
11+
const u: UserOpts = { delay: 20 };
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": ["dom", "es6"],
5+
"noImplicitAny": true,
6+
"noImplicitThis": true,
7+
"strictNullChecks": true,
8+
"strictFunctionTypes": true,
9+
"baseUrl": "../",
10+
"typeRoots": ["../"],
11+
"types": [],
12+
"noEmit": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": ["index.d.ts", "testing-library__user-event-tests.ts"]
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }

0 commit comments

Comments
 (0)