我正在尝试从expect迁移到柴和锡南。我希望我们做这样的事情
this.check = expect.spyOn(module, "method").andCall(function(dep) {
return dep;
});
但是我想要柴和诗乃的这种行为。
this.check = sinon.spy(module, "method")
但是当我参考文档时我如何获得andCall
,我猜想callsFake
不能调用spy
,我并不认为stud
会有类似的行为。
感谢您的任何帮助。
您可以做这样的事情:
it('makes blue cheese', () => {
const mySpy = sinon.spy()
sinon.stub(module, 'method')
.callsFake((...args) => {
mySpy(...args)
// Do other stuff here like return a value
return 'blue cheese'
})
const testValue = module.method('hello', 'world')
expect(testValue).to.eq('blue cheese')
expect(testValue).calledWith('hello', 'world')
})
这种存根和调用间谍的方式在我使用Sinon 8.1.1
编写的测试中起作用。