2

I'm having a problem with QUnit stop() basically it doesn't seem to be working at all. Here's an example of something I'm trying to do: http://jsfiddle.net/7hZMM/1/

If you remove the line:

testIframe.remove();

It works fine and runs the test and passes.

I presumed that calling stop() would halt test execution (as the docs say it should) but that doesn't seem to be the case as the remove() is being called before the load callback is completed.

What can I do to make sure the test is run before the iframe is removed from the page?

I don't want to put the iframe remove in a callback as I have a few instances of this and will cause callback hell if I have to make each equal run off each other.

Tim
  • 7,660
  • 3
  • 30
  • 33

2 Answers2

2

This is not clear from the docs, but stop() just ensures that teardown for the test will not be started until start() has been called. It does not in any way postpone the statements in the current test case following the call to stop().

The correct answer to your question is the one provided by jhorback; put the removal in the teardown.

Godsmith
  • 2,492
  • 30
  • 26
0

You could try putting the removal in the teardown of the module. This would wait until the start() method is called and the text execution is complete.

QUnit.module("new test", {
    setup: function () {
        var testIframe = $('<iframe id="testiframe" src="/" />').appendTo("body");
        testIframe.load(function() {
            console.log('done loading iframe');
        });                              
    },

    teardown: function () {
       testIframe.remove();
    }
});

QUnit.stop only tells QUnit to wait so many miliseconds before checking the results. Also, the iframe load event may not be triggered if the iframe does not have a valid src.

jhorback
  • 833
  • 8
  • 12