我有这样的父类:
'use strict';
class Test{
constructor(){
}
my_method(){
//some stuff here....
}
}
module.exports = Test;
这样的儿童班:
'use strict';
var Test = require('./test');
class ChildClass extends Test{
constructor(){
super();
}
some_other_method(){
//some code....
//
this.my_method();
//more code...
}
}
module.exports = ChildClass;
在我的测试中,我试图重新连接父类方法(' my_method')。像这样:
var rewire = require('rewire');
var Child = rewire('./child_class');
var Parent = rewire('./test');
describe("Test", function(){
beforeEach(function(){
this.some_other_func = () =>{
console.log('Do nothing...');
return;
};
Parent.__set__('my_method', this.some_other_func);
Child.__set__('Test', Parent);
});
it("some test....",() => {
var child = new Child();
child.some_other_method();
//test stuff...
});
});
但它没有用。 这是我第一次使用mocha重新连接,我做错了吗?