module.exports.rewire = function(module, autoReset, afterEachHook) {
  var rewiredNames = [];
  if (typeof autoReset === 'undefined') {
    autoReset = true;
  }
  if (typeof afterEachHook === 'undefined') {
    afterEachHook = afterEach;
  }

  function reset() {
    rewiredNames.forEach(function(name) {
      module.__ResetDependency__(name);
    });
    rewiredNames.length = 0;
  }

  if (autoReset) {
    afterEachHook(reset);
  }

  return {
    replace: function(name, replacement) {
      module.__Rewire__(name, replacement);
      rewiredNames.push(name);
      return this;
    },

    replaceMap: function(replacementMap) {
      Object.keys(replacementMap).forEach(function(name) {
        this.replace(name, replacementMap[name]);
      });
      return this;
    },

    reset: function() {
      reset();
      return this;
    }
  };
};

module.exports.rewire = function(module, autoReset, afterEachHook) {
  var rewiredNames = [];
  if (typeof autoReset === 'undefined') {
    autoReset = true;
  }
  if (typeof afterEachHook === 'undefined') {
    afterEachHook = afterEach;
  }

  function reset() {
    rewiredNames.forEach(function(name) {
      module.__ResetDependency__(name);
    });
    rewiredNames.length = 0;
  }

  if (autoReset) {
    afterEachHook(reset);
  }

  return {
    replace: function(name, replacement) {
      module.__Rewire__(name, replacement);
      rewiredNames.push(name);
      return this;
    },

    replaceMap: function(replacementMap) {
      var that = this;
      Object.keys(replacementMap).forEach(function(name) {
        that.replace(name, replacementMap[name]);
      });
      return this;
    },

    reset: function() {
      reset();
      return this;
    }
  };
};

Fix execution context in replaceMap
Fix execution context in replaceMap
