Skip to content

Commit

Permalink
Handle request with undefined url
Browse files Browse the repository at this point in the history
  • Loading branch information
novascreen committed Jul 24, 2020
1 parent a0026dc commit 78fe012
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/handle_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ function makeResponse(result, config) {
}

function handleRequest(mockAdapter, resolve, reject, config) {
var url = config.url;
var url = config.url || "";
// TODO we're not hitting this `if` in any of the tests, investigate
if (
config.baseURL &&
config.url.substr(0, config.baseURL.length) === config.baseURL
url.substr(0, config.baseURL.length) === config.baseURL
) {
url = config.url.slice(config.baseURL.length);
url = url.slice(config.baseURL.length);
}

delete config.adapter;
Expand Down Expand Up @@ -120,7 +120,7 @@ function handleRequest(mockAdapter, resolve, reject, config) {
case "passthrough":
mockAdapter.originalAdapter(config).then(resolve, reject);
break;
case 'throwException':
case "throwException":
throw utils.createCouldNotFindMockError(config);
default:
utils.settle(
Expand Down
8 changes: 8 additions & 0 deletions test/pass_through.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ describe("passThrough tests (requires Node)", function () {
});
});

it("handle request with baseURL only", function () {
mock.onAny().passThrough();

return instance.get(undefined).then(function (response) {
expect(response.data).to.equal("/");
});
});

it("handles request transformations properly", function () {
mock.onGet("/foo").passThrough();

Expand Down

0 comments on commit 78fe012

Please sign in to comment.