Skip to content

Commit 4dd579f

Browse files
committed
ok we can unit test dataURL too
1 parent bac761c commit 4dd579f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/unit/tw_external.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,22 @@ test('fetch', t => {
1717
});
1818
});
1919

20-
// Node.js does not support FileReader (yet?) so not really possible to properly test dataURL
20+
test('dataURL', t => {
21+
global.FileReader = class {
22+
readAsDataURL (blob) {
23+
blob.arrayBuffer().then(arrayBuffer => {
24+
const base64 = Buffer.from(arrayBuffer).toString('base64');
25+
this.result = `data:${blob.type};base64,${base64}`;
26+
this.onload();
27+
});
28+
}
29+
};
30+
31+
external.dataURL('data:text/plain;,doesthiswork').then(dataURL => {
32+
t.equal(dataURL, `data:text/plain;base64,${btoa('doesthiswork')}`);
33+
t.end();
34+
});
35+
});
2136

2237
test('blob', t => {
2338
external.blob('data:text/plain;,test').then(blob => {

0 commit comments

Comments
 (0)