Skip to content
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

fix: [#1538] Always return Promise<Blob> from ClipboardItem.getType() method #1539

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/happy-dom/src/clipboard/ClipboardItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ export default class ClipboardItem {
* @param type Type.
* @returns Data.
*/
public async getType(type: string): Promise<Blob | string> {
public async getType(type: string): Promise<Blob> {
if (!this.#data[type]) {
throw new DOMException(
`Failed to execute 'getType' on 'ClipboardItem': The type '${type}' was not found`
);
}
return this.#data[type];
if (this.#data[type] instanceof Blob) {
return this.#data[type];
}
return new Blob([await this.#data[type]], { type });
}
}
8 changes: 3 additions & 5 deletions packages/happy-dom/test/clipboard/Clipboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ describe('Clipboard', () => {

for (const item of data) {
const data = await item.getType(item.types[0]);
if (typeof data === 'string') {
text += data;
} else {
text += await data.text();
}
expect(data).toBeInstanceOf(Blob);

text += await data.text();
}

expect(text).toBe('test-a<b>test-b</b>test-ctest-dtest-e');
Expand Down
Loading