SinonJS假定时器不工作与QUnit

SinonJS fake timer does not work with QUnit

本文关键字:QUnit 工作 定时器 SinonJS      更新时间:2023-09-26

我正在使用SinonJS和QUnit运行以下代码:

var clock = this.sandbox.useFakeTimers();
var el = jQuery("<div></div>");
el.appendTo(document.body);
el.animate({ height: "200px", width: "200px" });
clock.tick(1000);
equals("200px", el.css("height"));
equals("200px", el.css("width"));

但是测试失败了,看起来jQuery使用的是真正的时钟,而不是假的。

我使用Chrome 12.0.742.122.

任何想法?

谢谢

jQuery正在使用窗口。webkitRequestAnimationFrame或window。mozRequestAnimationFrame而不是setInterval.

如果您设置了窗口。在加载jQuery之前,将mozRequestAnimationFrame设置为false,它将使用setTimeout, SinonJS将正常工作。