You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Restore function affects the http.request unexpectly #24
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,
varassert=require('assert');varhttp=require('http');varmm=require('mm');varobj={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){thrownewError('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 invalidassert.equal(e.message,'Never want to send request out');}
It's fine if I use mm.http.request and there's a conflict with other lib which also changes http.request.
But even if I only use the stub feature(underlying muk), the mm.restore still touches the http.request by force. That's the problem I think mm.restore does too much.
Activity
alsotang commentedon Nov 30, 2015
This issue would occurs when
mmandnockbe used together?xavierchow commentedon Nov 30, 2015
Yes, also other modules which alter the underlying
http.request.alsotang commentedon Nov 30, 2015
it is most likely two hacks can not work correctly together..
I think this issue is inevitable, but yes we can attempt to avoid them
2015-11-30 11:09 GMT+08:00 xavier notifications@github.com:
xavierchow commentedon Nov 30, 2015
It's fine if I use
mm.http.requestand there's a conflict with other lib which also changeshttp.request.But even if I only use the stub feature(underlying muk), the
mm.restorestill touches thehttp.requestby force. That's the problem I thinkmm.restoredoes too much.