From c725e6294b25d3a7758937f8e512e46fcf3d2fb3 Mon Sep 17 00:00:00 2001 From: mAAdhaTTah Date: Fri, 27 Mar 2020 22:08:30 -0400 Subject: [PATCH] Add support for responseURL to fakeXHR Source: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL --- lib/fake-xhr/index.js | 2 ++ lib/fake-xhr/index.test.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/fake-xhr/index.js b/lib/fake-xhr/index.js index 9488f59..8be74c9 100644 --- a/lib/fake-xhr/index.js +++ b/lib/fake-xhr/index.js @@ -804,6 +804,8 @@ function fakeXMLHttpRequestFor(globalScope) { this.setStatus(status); this.setResponseHeaders(headers || {}); this.setResponseBody(body || ""); + + this.responseURL = this.url; }, uploadProgress: function uploadProgress(progressEventRaw) { diff --git a/lib/fake-xhr/index.test.js b/lib/fake-xhr/index.test.js index e6bd8b7..bd9eeec 100644 --- a/lib/fake-xhr/index.test.js +++ b/lib/fake-xhr/index.test.js @@ -1907,6 +1907,26 @@ describe("FakeXMLHttpRequest", function() { }); }); + describe(".responseURL", function() { + beforeEach(function() { + this.xhr = new FakeXMLHttpRequest(); + }); + + it("should set responseURL after response", function() { + this.xhr.open("GET", "/"); + + assert.isUndefined(this.xhr.responseURL); + + this.xhr.send(); + + assert.isUndefined(this.xhr.responseURL); + + this.xhr.respond(200, {}, ""); + + assert.equals(this.xhr.responseURL, "/"); + }); + }); + describe("stub XHR", function() { beforeEach(fakeXhrSetUp); afterEach(fakeXhrTearDown);