Skip to content

Commit e2069de

Browse files
committed
Create a mock for window.URL.createObjectURL
1 parent 4ec75cc commit e2069de

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

setupTests.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,22 @@ Object.defineProperty(window, 'location', {
5151
},
5252
writable: true,
5353
});
54-
window.__PRELOADED_STATE__ = { random: 'Preloaded state, baby!' };
54+
55+
function toArrayBuffer(buffer) {
56+
const arrayBuffer = new ArrayBuffer(buffer.length);
57+
const view = new Uint8Array(arrayBuffer);
58+
59+
for (let i = 0; i < buffer.length; ++i) {
60+
view[i] = buffer[i];
61+
}
62+
63+
return arrayBuffer;
64+
}
65+
66+
(window.URL.createObjectURL = (obj) => {
67+
return Buffer.from(toArrayBuffer(obj)).toString('base64url');
68+
}),
69+
(window.__PRELOADED_STATE__ = { random: 'Preloaded state, baby!' });
5570

5671
jest.mock('fhirclient', () => ({
5772
client: jest.fn().mockImplementation(() => {

0 commit comments

Comments
 (0)