我有一个myModule Node.js模块,它包含:
function b() {
console.log('original b');
}
function a() {
b();
}
exports.a = a
exports.b = b;下面的测试套件使用mocha + sinon.js:
const myModule = require('./myModule.js');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
chai.use(sinonChai);
describe('not working stub', () => {
it('should call the stub', () => {
let stub = sinon.stub(myModule, 'b', () => { console.log('stubbed b')});
myModule.a();
expect(stub).to.have.been.called;
})
});我期待存根被调用,但是原来的b被调用,为什么?
发布于 2019-01-31 21:41:20
var stub = sinon.stub(object,"method",func);
这已从v3.0.0中删除。相反,您应该使用存根(object,'method').callsFake(fn)。或者你可以使用.yields(fn)
https://stackoverflow.com/questions/42148484
复制相似问题