diff --git a/package.json b/package.json index ebe0f2b..b5e5976 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "url": "https://github.com/M6Web/superagent-mock" }, "peerDependencies": { - "superagent": "^3.5.2" + "superagent": "^3.6.0" }, "devDependencies": { "babel-cli": "^6.24.1", @@ -25,7 +25,7 @@ "eslint": "^3.19.0", "jest": "20.0.3", "rimraf": "^2.6.1", - "superagent": "^3.5.2" + "superagent": "^3.6.0" }, "scripts": { "clean": "rimraf lib es", diff --git a/src/superagent-mock.js b/src/superagent-mock.js index 13add7c..9fcf892 100755 --- a/src/superagent-mock.js +++ b/src/superagent-mock.js @@ -86,17 +86,28 @@ module.exports = function (superagent, config, logger) { const isNodeServer = this.hasOwnProperty('cookies'); let response = {}; - if (isNodeServer) { // node server - const originalPath = this.path; - this.path = this.url; - this._appendQueryString(this); // use superagent implementation of adding the query - path = this.path; // save the url together with the query - this.path = originalPath; // reverse the addition of query to path by _appendQueryString - } else { // client + if (this._finalizeQueryString) { + // superagent 3.6+ + const originalUrl = this.url; - this._appendQueryString(this); // use superagent implementation of adding the query - path = this.url; // save the url together with the query - this.url = originalUrl; // reverse the addition of query to url by _appendQueryString + isNodeServer ? this.request() : this._finalizeQueryString(this); + path = this.url; + this.url = originalUrl; + } else { + // superagent < 3.6 + + if (isNodeServer) { // node server + const originalPath = this.path; + this.path = this.url; + this._appendQueryString(this); // use superagent implementation of adding the query + path = this.path; // save the url together with the query + this.path = originalPath; // reverse the addition of query to path by _appendQueryString + } else { // client + const originalUrl = this.url; + this._appendQueryString(this); // use superagent implementation of adding the query + path = this.url; // save the url together with the query + this.url = originalUrl; // reverse the addition of query to url by _appendQueryString + } } // Attempt to match path against the patterns in fixtures