Skip to content

Commit 759b4fb

Browse files
fix: [#1538] Always return Promise<Blob> from ClipboardItem.getType() (#1539)
Co-authored-by: David Ortner <[email protected]>
1 parent 33a72ca commit 759b4fb

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/happy-dom/src/clipboard/ClipboardItem.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ export default class ClipboardItem {
4343
* @param type Type.
4444
* @returns Data.
4545
*/
46-
public async getType(type: string): Promise<Blob | string> {
46+
public async getType(type: string): Promise<Blob> {
4747
if (!this.#data[type]) {
4848
throw new DOMException(
4949
`Failed to execute 'getType' on 'ClipboardItem': The type '${type}' was not found`
5050
);
5151
}
52-
return this.#data[type];
52+
if (this.#data[type] instanceof Blob) {
53+
return this.#data[type];
54+
}
55+
return new Blob([await this.#data[type]], { type });
5356
}
5457
}

packages/happy-dom/test/clipboard/Clipboard.test.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ describe('Clipboard', () => {
3737

3838
for (const item of data) {
3939
const data = await item.getType(item.types[0]);
40-
if (typeof data === 'string') {
41-
text += data;
42-
} else {
43-
text += await data.text();
44-
}
40+
expect(data).toBeInstanceOf(Blob);
41+
42+
text += await data.text();
4543
}
4644

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

0 commit comments

Comments
 (0)