Skip to content

Commit

Permalink
fix: [#1538] Always return Promise<Blob> from ClipboardItem.getType() (
Browse files Browse the repository at this point in the history
…#1539)

Co-authored-by: David Ortner <david@ortner.se>
  • Loading branch information
ezzatron and capricorn86 authored Nov 3, 2024
1 parent 33a72ca commit 759b4fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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

0 comments on commit 759b4fb

Please sign in to comment.