Here's proof that I'm new to QUnit! I was trying to put the test
thread to sleep - obviously that's the wrong paradigm.

I broke the test into 2 tests, and this seems to satisfy what I'm
trying to do:


test("updateWaitState shows element", function() {
        $("div.mydiv").hide();

        $("div.mydiv").updateWaitState("This is a message");
        equals($("div.mydiv").css('visibility'), 'visible', "Sets element to
visible");
});

test("updateWaitState fades element", function() {
        expect(1);

        stop();
        $("div.mydiv").updateWaitState("This is a message", function() {
                ok(true, "callback function was called");
                start();
        });
});



On Nov 20, 9:08 am, todd <[EMAIL PROTECTED]> wrote:
> 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