Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blob support to passthrough (UPDATED) #349

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/create-passthrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function createPassthrough(fakeXHR, nativeXMLHttpRequest) {
fakeXHR.password
);

if (fakeXHR.responseType === 'arraybuffer') {
if (fakeXHR.responseType === 'arraybuffer' || fakeXHR.responseType === 'blob') {
lifecycleProps = ['readyState', 'response', 'status', 'statusText'];
xhr.responseType = fakeXHR.responseType;
}
Expand Down
33 changes: 33 additions & 0 deletions test/passthrough_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,39 @@ describe('passthrough requests', function (config) {
}
);

it(
'asynchronous request with pass-through and ' +
'blob as responseType',
function(assert) {
var pretender = this.pretender;
var done = assert.async();

function testXHR() {
this.pretender = pretender;
this.open = function() {};
this.setRequestHeader = function() {};
this.upload = {};
this.responseType = '';
this.send = {
pretender: pretender,
apply: function(xhr, argument) {
assert.equal(xhr.responseType, 'blob');
this.pretender.resolve(xhr);
done();
}
};
}
pretender._nativeXMLHttpRequest = testXHR;

pretender.get('/some/path', pretender.passthrough);

var xhr = new window.XMLHttpRequest();
xhr.open('GET', '/some/path');
xhr.responseType = 'blob';
xhr.send();
}
);

it('synchronous request has timeout=0, withCredentials and onprogress event', function (assert) {
var pretender = this.pretender;
var done = assert.async();
Expand Down