User-event: Paste eventInit Type should be ClipboardEventInit

Created on 2 Dec 2020  路  4Comments  路  Source: testing-library/user-event

  • @testing-library/user-event version: 12.3.0

  • Testing Framework and version: Not Relevant

  • DOM Environment: Not Relevant

Relevant code or config
https://github.com/testing-library/user-event/blob/master/typings/index.d.ts#L65

What you did:

When using user-event in typescript, I wanted to pass in clipboardData into the eventInit arg of paste, as directed by the README: https://github.com/testing-library/user-event/blob/master/README.md#pasteelement-text-eventinit-options

What happened:

I get a type error indicating that clipboardData is not found on MouseEventInit

Reproduction repository:

I'd be happy to put a repro repo, but the issue and fix seem straightforward.

Problem description:

The eventInit arg in paste is of type MouseEventInit.

Suggested solution:

The eventInit arg in paste should be type ClipboardEventInit. (https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules_typedoc_node_modules_typescript_lib_lib_dom_d_.clipboardeventinit.html)

bug good first issue

All 4 comments

How did you create clipboardData? Are you using a raw JS object? JSDOM doesn't implement ClipboardData (see https://github.com/jsdom/jsdom/issues/1568).

If you need a proper value of clipboardData passed automatically when calling paste, I'm tracking support for custom implementations of ClipboardData and DataTransfer in https://github.com/testing-library/user-event/issues/355#issuecomment-642941030. If you just need the type fixed we can fix that separately.

I just need the type fixed. I'm actually using the library in a hacky fashion in the browser haha

https://github.com/dvargas92495/roam-js-extensions/blob/master/src/components/WikiData.tsx#L82

A PR correcting typings would be very much welcomed :)

@ph-fritsche - I've attempted to create a type fix PR in #611

Was this page helpful?
0 / 5 - 0 ratings