有沒有一種方法可以輕鬆地重置所有的sinon spys mock和存根,這些都可以用摩卡的beforeEach塊清理工作。很容易清理sinon存根
我看到沙盒是一種選擇,但我不看你如何使用沙箱這個
beforeEach ->
sinon.stub some, 'method'
sinon.stub some, 'mother'
afterEach ->
# I want to avoid these lines
some.method.restore()
some.other.restore()
it 'should call a some method and not other', ->
some.method()
assert.called some.method
如果我讀的http:// sinonjs .org/docs /#sinon-test正確地在你的'sinon.test'例子中,你應該使用'this.stub(some,'method');' – EvdB 2013-05-29 07:53:23
@EvdB You'e right。固定。我*認爲*使用'sinon.stub()'也可以,但更好地發揮它的安全性並堅持它的記錄方式。 – keithjgrant 2013-05-30 21:09:22
它似乎是強制性的:「如果你不想手動restore()',你必須使用'this.spy()'而不是'sinon.spy()'(和'stub','mock ')「。 – 2013-06-12 07:14:52