1
我有以下sinon.js/chai.js測試我的JavaScript類。爲什麼我的測試函數嘲笑時間在某些環境下永遠不會完成?
describe('tick', function() {
beforeEach(function() {
this.clock = sinon.useFakeTimers();
});
afterEach(function() {
this.clock = sinon.restore();
});
it('should increase the time waited for all translators', function() {
let queue = new TranslatorQueue();
queue.join("translator1");
this.clock.tick(1000);
expect(_.head(queue.queue).timeWaiting).to.equal(1);
queue.join("translator2");
this.clock.tick(1000);
expect(_.head(queue.queue).timeWaiting).to.equal(2);
expect(_.last(queue.queue).timeWaiting).to.equal(1);
});
});
測試通過我的開發機上很好,但測試永遠不會完成並出現在嘗試運行我的臨時服務器上測試時,進入無限循環。我想這與嘲笑計時器有關,但我該如何解決這個問題呢?
哈哈我喜歡這種情況。它被稱爲[橡皮鴨調試](https://spin.atomicobject.com/2015/08/18/rubber-duck-debugging/):-) – Thatkookooguy