From 78fe012420675e4c1a0e06f31d72aca846ab1232 Mon Sep 17 00:00:00 2001 From: Thomas Hermann <1596280+novascreen@users.noreply.github.com> Date: Fri, 24 Jul 2020 10:37:32 -0400 Subject: [PATCH] Handle request with undefined url --- src/handle_request.js | 8 ++++---- test/pass_through.spec.js | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/handle_request.js b/src/handle_request.js index 277e034..d16be1c 100644 --- a/src/handle_request.js +++ b/src/handle_request.js @@ -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; @@ -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( diff --git a/test/pass_through.spec.js b/test/pass_through.spec.js index 8e7774a..3e3ba3a 100644 --- a/test/pass_through.spec.js +++ b/test/pass_through.spec.js @@ -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();