Skip to content

Restore function affects the http.request unexpectly #24

Open
@xavierchow

Description

@xavierchow

Some other libraries such as nock also alter the http.request, as long as you require the mm, even you don't use the mm.http.request, the restore changes it with the origin one(at the context of require moment) by force, which is not expected, see sample below,

var assert = require('assert');
var http = require('http');
var mm = require('mm');

var obj = {
  foo: function () {
    console.log('original foo called');
  }
};
mm(obj, 'foo', function () {
  console.log("mocked foo called");
});
obj.foo();

//Manually override the http.request for certain purpose.
http.request = function (option, callback) {
 throw new Error('Never want to send request out');
} 

mm.restore();
try {
  http.get({ path: '/foo' }, function (res) {});
} catch (e) {
  //assert here failed, because the restore made the overriding above invalid
  assert.equal(e.message, 'Never want to send request out');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions