各テストの前に Sinon スパイの「呼び出された」カウントをリセットするにはどうすればよいですか?
これが私が今していることです:
beforeEach(function() {
this.spied = sinon.spy(Obj.prototype, 'spiedMethod');
});
afterEach(function() {
Obj.prototype.spiedMethod.restore();
this.spied.reset();
});
しかし、テストで呼び出し回数を確認すると:
it('calls the method once', function() {
$.publish('event:trigger');
expect(this.spied).to.have.been.calledOnce;
});
...テストは失敗し、メソッドが X 回呼び出されたことを報告します (同じイベントをトリガーした以前のテストごとに 1 回)。