From 77116dfc0a36e5817825baade19b3ee0de3dbba3 Mon Sep 17 00:00:00 2001 From: maxkoryukov Date: Sat, 11 Feb 2017 18:22:57 +0500 Subject: [PATCH] Mocking for the `field` method of superagent --- index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/index.js b/index.js index 48de34e..3c1385d 100644 --- a/index.js +++ b/index.js @@ -150,6 +150,24 @@ function mock(superagent) { return this; }; + // Patch Request.field() + var oldField = originalMethods.field = reqProto.field; + reqProto.field = function(key, val) { + var state = this._superagentMockerState; + if (!state || !state.current) { + return oldField.call(this, key, val); + } + // Recursively prop keys if passed an object + if (isObject(key)) { + for (var prop in key) { + this.field(prop, key[prop]); + } + return this; + } + state.request.body[key] = val; + return this; + }; + // Patch Request.query() var oldQuery = originalMethods.query = reqProto.query; reqProto.query = function(objectOrString) {