diff --git a/src/Angular.js b/src/Angular.js index 56d724d98fc2..e55d5f7437fc 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -913,6 +913,9 @@ function copy(source, destination) { var re = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]); re.lastIndex = source.lastIndex; return re; + + case '[object Blob]': + return new source.constructor([source], {type: source.type}); } if (isFunction(source.cloneNode)) { diff --git a/test/AngularSpec.js b/test/AngularSpec.js index e64abb9e5229..21b711a1524c 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -228,6 +228,18 @@ describe('angular', function() { } }); + it('should handle Blob objects', function() { + if (typeof Blob !== 'undefined') { + var src = new Blob(['foo'], {type: 'bar'}); + var dst = copy(src); + + expect(dst).not.toBe(src); + expect(dst.size).toBe(3); + expect(dst.type).toBe('bar'); + expect(isBlob(dst)).toBe(true); + } + }); + it("should throw an exception if a Uint8Array is the destination", function() { if (typeof Uint8Array !== 'undefined') { var src = new Uint8Array(); diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 79cd5dce0799..0b2bce19525d 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -1011,6 +1011,26 @@ describe('ngMock', function() { }); + it('should be able to handle Blobs as mock data', function() { + if (typeof Blob !== 'undefined') { + var mockBlob = new Blob(['{"foo":"bar"}'], {type: 'application/json'}); + + hb.when('GET', '/url1').respond(200, mockBlob, {}); + + callback.andCallFake(function(status, response) { + expect(response).not.toBe(mockBlob); + expect(response.size).toBe(13); + expect(response.type).toBe('application/json'); + expect(response.toString()).toBe('[object Blob]'); + }); + + hb('GET', '/url1', null, callback); + hb.flush(); + expect(callback).toHaveBeenCalledOnce(); + } + }); + + it('should throw error when unexpected request', function() { hb.when('GET', '/url1').respond(200, 'content'); expect(function() {