Asynchronous tests run twice in standalone #613

schickling opened this Issue Jun 18, 2014 · 10 comments


None yet

7 participants


When running the standalone version of jasmine tests (asynchronous) run twice. The log looks something like this:

TestA starts
TestA done asynchronously
TestB starts
TestB done asynchronously
TestA starts
TestA done asynchronously
TestB starts
TestB done asynchronously
TestC starts
TestC done asynchronously

As far as I can see the tests/jasmine are not loaded twice.

It might be important to note, that I'm running the jasmine standalone version inside a Cordova application on an iOS device. I initialize the tests like the following, since I need to wait for cordova to finish loading:

var loadScript = function(src) {
  var el = document.createElement('script')
  el.setAttribute('src', src);
  el.async = false;

var loadTests = function() {

  // timeout and window.onload needed to start tests
  setTimeout(function() {
  }, 1000);

document.addEventListener('deviceready', loadTests, false);
infews commented Jun 23, 2014

Are you able to duplicate this in a desktop browser?

ohana54 commented Sep 8, 2014

I don't know if it's the same issue, but I'm encountering something similar with Chrome.
I'm running the tests using Karma.
I only have one test defined. When it is a regular test, it runs only once.
If I change it to an async test, it runs 3 times according to the log:
Chrome 37.0.2062 (Mac OS X 10.9.4): Executed 3 of 1 SUCCESS (0.004 secs / 0.001 secs)


How exactly are you changing it to async? As long as you only call done once in the spec it should only report once. In jasmine 2.0.0, calling the done callback multiple times #523 or doing more work after calling done #549 would erroneously report more than once. These issues were fixed in 2.0.1. Please make sure you're on the most recent version of jasmine.

@slackersoft slackersoft added the waiting label Oct 10, 2014

We haven't heard anything else on this issue from the community, so I'm going to close this. Feel free to re-open or start a new issue if you're still seeing this on the most recent jasmine.


In case someone faces this issue in Karma + Jasmine setup, check if you have karma-jasmine >0.3.0. Since 0.3.0, karma-jasmine has stopped bundling jasmine and hence you can update the versions easily. I'm now on karma-jasmine 0.3.3 and jasmine-core 2.1.3 and the issue has been fixed for me.

Karma Jasmine docs


teo-sk commented Feb 24, 2015

@shashankmehta oh my glob you just saved me after 3 hours of debugging :'D


Happens for me right now. I have one test:

  describe('#scrollToRow', function () {
    var bgt;
    beforeEach(function (done) {
      bgt = new BGT(defaultOpts);
      bgt.addListener('rowsbuilt', function () { done(); });
    afterEach(function () {
    it('scrolls to the row so the scrollTop is equal to the row height x index in the table', function (done) {
      // Note for testing we just assume all rows are 10px (see Clusterize stub)
      var els = bgt.getElements();


      bgt.addListener('rowsbuilt', function () {

The output of that is

karma debug runner 2016-02-11 15-15-15

This makes it super hard to deal with because at least if it duplicated the before/afters I could clean up and the test should work, but these tests are failing because the scrollTops are altered from the previous tests.


Oh, and I upgraded Jasmine and Karma like suggested, reset the server, etc and still that happens


@OscarGodson what version of Jasmine are you using? From what I can see in your test it looks like the rowsbuilt listener from the beforeEach is being called again during the spec which is causing the spec to execute again. This should have been fixed in #523 in version 2.0.1.

You could also try removing that handler after it is executed the first time and see if that fixes the issue.

Thanks for using Jasmine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment