-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clipboard API #1568
Comments
A pull request adding support for this would definitely be welcome. |
Is there any plan to support DataTransfer? It would help with an issue I'm having testing onDrop events using react-testing-library |
It's no full implementation to be sure.. but depending what you want out of the |
I tried to mock ClipBoardEvent same as you did import { implementation } from 'jsdom/lib/jsdom/living/events/Event-impl';
// @ts-ignore
class ClipboardEventMock extends implementation implements ClipboardEvent {
public readonly clipboardData: DataTransfer | null;
public constructor(type: string, eventInitDict?: ClipboardEventInit) {
super(type, eventInitDict);
this.clipboardData = eventInitDict?.clipboardData || null;
}
}
Object.defineProperty(window, 'ClipboardEvent', {
writable: true,
value: jest.fn().mockImplementation((type, eventInitDict) => new ClipboardEventMock(type, eventInitDict)),
}); but got a quiet wired result |
@icy0307 Instead of reaching into |
I just ran into this issue while trying to test my file type input with a drop event. |
The simplest sane workaround I can think of is to implement class MockClipboardEvent extends Event implements ClipboardEvent {
clipboardData: DataTransfer | null = null;
} And then at the start of every test or script, do this: window.ClipboardEvent = MockClipboardEvent; If you need to perform test assertions of otherwise manipulate the export interface MockClipboardEvent extends ClipboardEvent {
// Declare any extra stuff you need for testing.
foo(): void;
}
export function createMockClipboardEventClass() {
const instances: MockClipboardEvent[] = [];
class _MockClipboardEvent extends Event implements MockClipboardEvent {
clipboardData: DataTransfer | null;
constructor(type: string, eventInitDict?: ClipboardEventInit) {
super(type, eventInitDict);
this.clipboardData = null;
instances.push(this);
}
// Any extra stuff you need for testing.
foo() {
console.log(this.clipboardData);
}
}
return {
class: _MockClipboardEvent,
instances,
};
} Then in your tests, you can check which clipboard events were created and what they contained, and even manipulate them in flight. |
Hi,
I don't see any implementation of the clipboard api, with the DataTransfer, DataTransferItemList and DataTransferItemListItem objects. Is there any plan supporting it?
The text was updated successfully, but these errors were encountered: