// a.js
var evil = require('evil');
module.exports = () => { evil.castCurse(); };
// b.js
var Evil = require('evil');
module.exports = () => { Evil.castCurse(); };
// main.js
var a = require('a.js');
var b = require('b.js');
module.exports = { a, b };
所以我的问题是-如果我将main-spec.js
加载为:
// main-spec.js
var rewire = require('rewire'),
main = rewire(../../../main.js');
main.__set__('Evil', {});
main.__set__('evil', {});
我是否需要做些其他事情?
// main-spec.js
var rewire = require('rewire'),
main = rewire(../../../main.js');
main.__get__('a').__set__('evil', { castCurse: () => { console.log('lucky a!'); }});
main.__get__('b').__set__('Evil', { castCurse: () => { console.log('lucky b!'); }});