Skip to content

Commit

Permalink
Allow Blob Responses
Browse files Browse the repository at this point in the history
  • Loading branch information
thefat32 committed May 15, 2021
1 parent 103f8a5 commit 8dd3039
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
"dependencies": {
"fast-deep-equal": "^3.1.3",
"is-blob": "^2.1.0",
"is-buffer": "^2.0.5"
},
"bundlesize": [
Expand Down
3 changes: 2 additions & 1 deletion src/handle_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function transformRequest(data) {
if (
utils.isArrayBuffer(data) ||
utils.isBuffer(data) ||
utils.isStream(data)
utils.isStream(data) ||
utils.isBlob(data)
) {
return data;
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var axios = require("axios");
var isEqual = require("fast-deep-equal");
var isBuffer = require("is-buffer");
var isBlob = require("is-blob");
var toString = Object.prototype.toString;

// < 0.13.0 will not have default headers set on a custom instance
Expand Down Expand Up @@ -197,6 +198,7 @@ module.exports = {
isFunction: isFunction,
isObjectOrArray: isObjectOrArray,
isBuffer: isBuffer,
isBlob: isBlob,
isEqual: isEqual,
createAxiosError: createAxiosError,
createCouldNotFindMockError: createCouldNotFindMockError,
Expand Down
18 changes: 18 additions & 0 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var expect = require("chai").expect;
var find = require("../src/utils").find;
var isEqual = require("../src/utils").isEqual;
var isObjectOrArray = require("../src/utils").isObjectOrArray;
var isBlob = require("../src/utils").isBlob;

describe("utility functions", function () {
context("find", function () {
Expand Down Expand Up @@ -63,4 +64,21 @@ describe("utility functions", function () {
expect(isObjectOrArray("1")).to.be.false;
});
});

context("isBlob", function () {
it("returns false for anything that is not a Blob", function () {
expect(isBlob(true)).to.be.false;
expect(isBlob(false)).to.be.false;
expect(isBlob(null)).to.be.false;
expect(isBlob(undefined)).to.be.false;
expect(isBlob(function () {})).to.be.false;
expect(isBlob(0)).to.be.false;
expect(isBlob(1)).to.be.false;
expect(isBlob("")).to.be.false;
expect(isBlob(" ")).to.be.false;
expect(isBlob("1")).to.be.false;
expect(isBlob({ foo: "bar" })).to.be.false;
expect(isBlob([1, 2, 3])).to.be.false;
});
});
});

0 comments on commit 8dd3039

Please sign in to comment.