Tak*_*hii 2 javascript clock jasmine
我的代码中有这个语句,我想知道如何使用 Jasmine 测试 setInterval。
const x = setInterval(() => {
const countdown = getElementById('countdownWrapper');
const systemTime = ...
const now = new Date().getTime();
const endTime = systemTime - now;
countdown.querySelector('.countdown-time').innerHTML = time();
if (endTime < 0) {
clearInterval(x);
countdown.classList.remove('countdown-time--show');
}
}, 1000);
Run Code Online (Sandbox Code Playgroud)
systemTime 由 HTML 中 DATA-CONTENT 属性中的纪元值提供。
任何帮助将不胜感激
beforeEach(function() {
timerCallback = jasmine.createSpyObj("setInterval");
jasmine.clock().install();
});
afterEach(function() {
jasmine.clock().uninstall();
});
it("causes a timeout to be called", function() {
setTimeout(function() {
timerCallback();
}, 1000);
expect(setInterval).not.toHaveBeenCalled();
jasmine.clock().tick(1001);
expect(setInterval).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4524 次 |
| 最近记录: |