diff --git a/package.json b/package.json index 9e4ee802..86b04912 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "version": "0.0.0-semantically-released", "description": "Fire events the same way the user does", "main": "dist/index.js", - "typings": "typings/index.d.ts", "keywords": [ "react-testing-library", "dom-testing-library", @@ -25,8 +24,7 @@ }, "homepage": "https://github.com/testing-library/user-event#readme", "files": [ - "dist", - "typings/index.d.ts" + "dist" ], "scripts": { "build": "kcd-scripts build", @@ -36,7 +34,7 @@ "test:debug": "kcd-scripts --inspect-brk test --runInBand", "test:update": "npm test -- --updateSnapshot --coverage", "validate": "kcd-scripts validate", - "typecheck": "kcd-scripts typecheck --build typings" + "typecheck": "kcd-scripts typecheck" }, "dependencies": { "@babel/runtime": "^7.12.5" diff --git a/src/clear.d.ts b/src/clear.d.ts new file mode 100644 index 00000000..7c3e18ca --- /dev/null +++ b/src/clear.d.ts @@ -0,0 +1 @@ +export declare function clear(element: Element): void diff --git a/src/click.d.ts b/src/click.d.ts index 57ac45fc..cf9fffc1 100644 --- a/src/click.d.ts +++ b/src/click.d.ts @@ -4,7 +4,9 @@ export declare interface clickOptions { } export declare function click( - element: TargetElement, + element: Element, init?: MouseEventInit, options?: clickOptions, ): void + +export declare function dblClick(element: Element, init?: MouseEventInit): void diff --git a/typings/dom-helpers.d.ts b/src/dom-helpers.d.ts similarity index 100% rename from typings/dom-helpers.d.ts rename to src/dom-helpers.d.ts diff --git a/src/index.js b/src/index.ts similarity index 79% rename from src/index.js rename to src/index.ts index 28e4750a..1d241393 100644 --- a/src/index.js +++ b/src/index.ts @@ -1,12 +1,12 @@ import {click, dblClick} from './click' -import {type, specialCharMap} from './type' +import {type} from './type' import {clear} from './clear' import {tab} from './tab' import {hover, unhover} from './hover' import {upload} from './upload' import {selectOptions, deselectOptions} from './select-options' import {paste} from './paste' -import {keyboard} from './keyboard' +import {keyboard, specialCharMap} from './keyboard' const userEvent = { click, @@ -26,3 +26,4 @@ const userEvent = { export default userEvent export {specialCharMap as specialChars} +export type {keyboardKey} from './keyboard' diff --git a/src/paste.d.ts b/src/paste.d.ts new file mode 100644 index 00000000..540c7c37 --- /dev/null +++ b/src/paste.d.ts @@ -0,0 +1,9 @@ +export declare function paste( + element: Element, + text: string, + init?: MouseEventInit, + pasteOptions?: { + initialSelectionStart?: number + initialSelectionEnd?: number + }, +): void diff --git a/src/select-options.d.ts b/src/select-options.d.ts new file mode 100644 index 00000000..7cc0788d --- /dev/null +++ b/src/select-options.d.ts @@ -0,0 +1,11 @@ +export declare function selectOptions( + element: Element, + values: HTMLElement | HTMLElement[] | string[] | string, + init?: MouseEventInit, +): void + +export declare function deselectOptions( + element: Element, + values: HTMLElement | HTMLElement[] | string[] | string, + init?: MouseEventInit, +): void diff --git a/src/tab.d.ts b/src/tab.d.ts new file mode 100644 index 00000000..7fc01d1d --- /dev/null +++ b/src/tab.d.ts @@ -0,0 +1,6 @@ +interface tabOptions { + shift?: boolean + focusTrap?: Document | Element +} + +export declare function tab(userOpts?: tabOptions): void diff --git a/src/upload.d.ts b/src/upload.d.ts new file mode 100644 index 00000000..3304a709 --- /dev/null +++ b/src/upload.d.ts @@ -0,0 +1,15 @@ +interface uploadInit { + clickInit?: MouseEventInit + changeInit?: Event +} + +interface uploadOptions { + applyAccept?: boolean +} + +export declare function upload( + element: Element, + files: File | File[], + init?: uploadInit, + options?: uploadOptions, +): void diff --git a/typings/.eslintrc b/typings/.eslintrc deleted file mode 100644 index 3f37c32e..00000000 --- a/typings/.eslintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "parserOptions": { - "project": "./typings/tsconfig.json" - } -} diff --git a/typings/index.d.ts b/typings/index.d.ts deleted file mode 100644 index 3d4ae385..00000000 --- a/typings/index.d.ts +++ /dev/null @@ -1,73 +0,0 @@ -import type {click, clickOptions} from '../src/click' -import type { - keyboard, - keyboardOptions, - specialCharMap, - keyboardKey, -} from '../src/keyboard' -import type {type, typeOptions} from '../src/type' - -// Definitions by: Wu Haotian -export interface ITabUserOptions { - shift?: boolean - focusTrap?: Document | Element -} - -export type TargetElement = Element - -export type FilesArgument = File | File[] - -export type UploadInitArgument = { - clickInit?: MouseEventInit - changeInit?: Event -} - -export interface IUploadOptions { - applyAccept?: boolean -} - -declare const userEvent: { - clear: (element: TargetElement) => void - click: typeof click - dblClick: ( - element: TargetElement, - init?: MouseEventInit, - options?: IClickOptions, - ) => void - selectOptions: ( - element: TargetElement, - values: HTMLElement | HTMLElement[] | string[] | string, - init?: MouseEventInit, - ) => void - deselectOptions: ( - element: TargetElement, - values: HTMLElement | HTMLElement[] | string[] | string, - init?: MouseEventInit, - ) => void - upload: ( - element: TargetElement, - files: FilesArgument, - init?: UploadInitArgument, - options?: IUploadOptions, - ) => void - type: typeof type - keyboard: typeof keyboard - tab: (userOpts?: ITabUserOptions) => void - paste: ( - element: TargetElement, - text: string, - init?: MouseEventInit, - pasteOptions?: { - initialSelectionStart?: number - initialSelectionEnd?: number - }, - ) => void - hover: (element: TargetElement, init?: MouseEventInit) => void - unhover: (element: TargetElement, init?: MouseEventInit) => void -} - -export default userEvent - -export {keyboardOptions, keyboardKey, specialCharMap as specialChars} -export {typeOptions, typeOptions as ITypeOpts} -export {clickOptions, clickOptions as IClickOptions} diff --git a/typings/test.ts b/typings/test.ts deleted file mode 100644 index a0449e4d..00000000 --- a/typings/test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import userEvent, {TargetElement} from '.' - -declare const element: TargetElement - -userEvent.type(element, 'foo', {delay: 1}).then( - // eslint-disable-next-line @typescript-eslint/no-invalid-void-type - function handleSucces(_nothing: void) {}, - function handleError(_error: Error) {}, -) -userEvent.type(element, 'foo') as undefined diff --git a/typings/tsconfig.json b/typings/tsconfig.json deleted file mode 100644 index a7829065..00000000 --- a/typings/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../node_modules/kcd-scripts/shared-tsconfig.json", - "include": ["."] -}