Skip to content

Commit

Permalink
Return deep clone of mock data in response
Browse files Browse the repository at this point in the history
closes #46
  • Loading branch information
ctimmerm committed Apr 14, 2017
1 parent 4a13822 commit 2fa2374
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 187 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"axios": ">= 0.9.0"
},
"devDependencies": {
"axios": "^0.15.2",
"axios": "^0.16.1",
"chai": "^3.5.0",
"cross-env": "^3.2.3",
"eslint": "^3.17.1",
"cross-env": "^4.0.0",
"eslint": "^3.19.0",
"istanbul": "^0.4.5",
"mocha": "^3.1.2",
"rimraf": "^2.6.1",
"webpack": "^2.2.1"
"webpack": "^2.3.3"
},
"dependencies": {
"deep-equal": "^1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion src/handle_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var utils = require('./utils');
function makeResponse(result, config) {
return {
status: result[0],
data: result[1],
data: utils.isObject(result[1]) ? JSON.parse(JSON.stringify(result[1])) : result[1],
headers: result[2],
config: config
};
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ VERBS.concat('any').forEach(function(method) {
MockAdapter.prototype[methodName] = function(matcher, body) {
var _this = this;
var matcher = matcher === undefined ? /.*/ : matcher;

function reply(code, response, headers) {
var handler = [matcher, body, code, response, headers];
addHandler(method, _this.handlers, handler);
return _this;
}

return {
reply: reply,

Expand Down
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ function createErrorResponse(message, config, response) {
return error;
}

function isObject(value) {
return value !== null && typeof value === 'object';
}

module.exports = {
find: find,
findHandler: findHandler,
isObject: isObject,
purgeIfReplyOnce: purgeIfReplyOnce,
settle: settle
};

0 comments on commit 2fa2374

Please sign in to comment.