I have this super simple method that I'm trying to test.

$.fn.updateWaitState = function(message, callback) {
                return this.css('color', 
'red').html(message).show().fadeOut(1000,
callback);
}

I want to make sure that the "fadeOut" is called. Here's what I've
tried:

with(jqUnit) {
        test("updateWaitState shows and fades element", function() {
                var wasCalled = false;

                $("div.mydiv").updateWaitState("This is a message", function
(wasCalled) {
                        wasCalled = true;
                        alert("Called " + wasCalled);
                        start();
                });

                equals($("div.mydiv").css('visibility'), 'visible', "Sets 
element to
visible");

                //Wait for callback function
                stop();

                ok(wasCalled, "fadeOut was called");
                alert("Done " + wasCalled);

        });
});

I'm sure the problem is not understanding the "stop" and "start"
methods. The order of popups confirms that "Done" is encountered
before the "Called" alert is triggered in the callback function.
Obviously, this causes the "ok" test to fail.

How do I get the script to stop until the callback function is fired?
Or is there a better way to test that fadeOut is applied?

Thanks in advance,

Todd

Reply via email to