index.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Definitions by: Wu Haotian <https://github.com/whtsky>
  2. export interface ITypeOpts {
  3. skipClick?: boolean
  4. skipAutoClose?: boolean
  5. delay?: number
  6. initialSelectionStart?: number
  7. initialSelectionEnd?: number
  8. }
  9. export interface ITabUserOptions {
  10. shift?: boolean
  11. focusTrap?: Document | Element
  12. }
  13. export type TargetElement = Element | Window
  14. export type FilesArgument = File | File[]
  15. export type UploadInitArgument = {
  16. clickInit?: MouseEventInit
  17. changeInit?: Event
  18. }
  19. export interface IClickOptions {
  20. skipHover?: boolean
  21. clickCount?: number
  22. }
  23. export interface IUploadOptions {
  24. applyAccept?: boolean
  25. }
  26. declare const userEvent: {
  27. clear: (element: TargetElement) => void
  28. click: (
  29. element: TargetElement,
  30. init?: MouseEventInit,
  31. options?: IClickOptions,
  32. ) => void
  33. dblClick: (
  34. element: TargetElement,
  35. init?: MouseEventInit,
  36. options?: IClickOptions,
  37. ) => void
  38. selectOptions: (
  39. element: TargetElement,
  40. values: string | string[] | HTMLElement | HTMLElement[],
  41. init?: MouseEventInit,
  42. ) => void
  43. deselectOptions: (
  44. element: TargetElement,
  45. values: string | string[] | HTMLElement | HTMLElement[],
  46. init?: MouseEventInit,
  47. ) => void
  48. upload: (
  49. element: TargetElement,
  50. files: FilesArgument,
  51. init?: UploadInitArgument,
  52. options?: IUploadOptions,
  53. ) => void
  54. type: <T extends ITypeOpts>(
  55. element: TargetElement,
  56. text: string,
  57. userOpts?: T,
  58. // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
  59. ) => T extends {delay: number} ? Promise<void> : void
  60. tab: (userOpts?: ITabUserOptions) => void
  61. paste: (
  62. element: TargetElement,
  63. text: string,
  64. init?: MouseEventInit,
  65. pasteOptions?: {
  66. initialSelectionStart?: number
  67. initialSelectionEnd?: number
  68. },
  69. ) => void
  70. hover: (element: TargetElement, init?: MouseEventInit) => void
  71. unhover: (element: TargetElement, init?: MouseEventInit) => void
  72. }
  73. export default userEvent
  74. export enum specialChars {
  75. arrowLeft = '{arrowleft}',
  76. arrowRight = '{arrowright}',
  77. arrowDown = '{arrowdown}',
  78. arrowUp = '{arrowup}',
  79. enter = '{enter}',
  80. escape = '{esc}',
  81. delete = '{del}',
  82. backspace = '{backspace}',
  83. home = '{home}',
  84. end = '{end}',
  85. selectAll = '{selectall}',
  86. space = '{space}',
  87. whitespace = ' ',
  88. }