Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting when jasmine tests complete

I am running jasmine tests like this;

   jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
   jasmine.getEnv().execute();

I would like to detect, using JavaScript, when the tests complete. How can I?

like image 873
Ben Flynn Avatar asked May 12 '11 15:05

Ben Flynn


2 Answers

As @Xv. suggests, adding a reporter will work. You can do something as simple as:

jasmine.getEnv().addReporter({
    jasmineDone: function () {
        // the specs have finished!
    }
});

See http://jasmine.github.io/2.2/custom_reporter.html.

like image 142
John Kurlak Avatar answered Sep 22 '22 19:09

John Kurlak


Some alternative ways:

A) Use the ConsoleRunner, that accepts an onComplete option. Older versions (1.2rc1) receive the complete callback as a standalone parameter.

Since you also supply the function that writes (options.print) you keep control about having the test reports written to the console.

You can have several reporters active at the same time jasmineEnv.addReporter().

B) Haven't tried, but you could create your own reporter, with empty implementations of every public method but jasmineDone()

C) Check an old post in the Jasmine google group, where the author saves and overrides jasmine.getEnv().currentRunner().finishCallback:

    var oldCallback = jasmineEnv.currentRunner().finishCallback;
    jasmineEnv.currentRunner().finishCallback = function () {
        oldCallback.apply(this, arguments);
        $("body").append( "<div id='_test_complete_signal_'></div" );   
    };
    jasmineEnv.execute();
like image 26
xverges Avatar answered Sep 23 '22 19:09

xverges