From 4a2c56c6492a66121fc291c74c7663e973b778f7 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 24 Oct 2014 22:17:23 -0400 Subject: [PATCH] more tests --- index.js | 8 +++++--- test/index.html | 2 ++ test/test.js | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 3e94597..9534ed9 100644 --- a/index.js +++ b/index.js @@ -86,10 +86,12 @@ function loadImage(src) { } function dataURLToBlob(dataURL) { - var type = dataURL.match(/data:([^;]+)/)[1]; - var base64 = dataURL.replace(/^[^,]+,/, ''); + return Promise.resolve().then(function () { + var type = dataURL.match(/data:([^;]+)/)[1]; + var base64 = dataURL.replace(/^[^,]+,/, ''); - return createBlob([binaryStringToArrayBuffer(atob(base64))], {type: type}); + return createBlob([binaryStringToArrayBuffer(atob(base64))], {type: type}); + }); } function createObjectURL(blob) { diff --git a/test/index.html b/test/index.html index 7daa13c..9f1c3cd 100644 --- a/test/index.html +++ b/test/index.html @@ -14,6 +14,8 @@
+ diff --git a/test/test.js b/test/test.js index 2af9446..8356fcf 100644 --- a/test/test.js +++ b/test/test.js @@ -86,5 +86,21 @@ function tests() { }); }); + it('convert data url', function () { + var dataURL = 'data:image/png;base64,' + transparent1x1Png; + return blobUtil.dataURLToBlob(dataURL).then(function (blob) { + return blobUtil.blobToBase64String(blob); + }).then(function (string) { + string.should.equal(transparent1x1Png); + }); + }); + + it('convert to dataURL', function () { + var img = document.getElementById('transparent'); + return blobUtil.imgSrcToDataURL(img.src).then(function (url) { + url.should.match(/^data:image\/png;base64/); + }); + }); + }); }