I have a function that use setInterval() method to watch css propertie change(’cause in some browser we don’t have event to do that), now I need to write an unit test for this function.
var counter = 0;
function callback() {
counter++;
}
$('body').append('<div id="testDom" style="color:red"/>');
dom = $('#testDom').get(0);
watcherId = DomWatcher.watch(dom, 'color', $.proxy(callback,this));
function testWatch() {
$(dom).css('color', 'green');
setTimeout(assertEqual(counter, 1), 1000);
}
Then the assertion fail.
I’m sure the watch function works well, it check css properties change every 100ms. Just don’t come up with a good way to write the unit test..
You are calling
assertEqualimmediately and passing it’s return value tosetTimeout. You need to pass a function tosetTimeout.