Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests start executing before page is loaded #77

Closed
astoilkov opened this issue Feb 22, 2015 · 2 comments
Closed

Tests start executing before page is loaded #77

astoilkov opened this issue Feb 22, 2015 · 2 comments

Comments

@astoilkov
Copy link

I am using karma-jasmine: 0.3.5. I have tests that run perfectly from a HTML runner that loads jasmine 2.2 but when I run them through karma using karma-jasmine they fail. I have investigated the problem and it seems that the tests start executing before the DOM is ready (which is not the case when run from a HTML runner). After updating the createStartFn function in the adapter.js file to the code below which waits for the DOM ready the tests started passsing.

function createStartFn(karma, jasmineEnv) {
  // This function will be assigned to `window.__karma__.start`:
  return function () {
    $(function () {
      jasmineEnv = jasmineEnv || window.jasmine.getEnv();

      jasmineEnv.addReporter(new KarmaReporter(karma, jasmineEnv));
      jasmineEnv.execute();
    });
  };
}
@maksimr
Copy link
Contributor

maksimr commented May 13, 2015

@astoilkov yup, You are right. Tests start before DOM is completed, but it's not issue of karma-jasmine, it is issue of karma. Because karma call start function.

As workaround you can create file jasmine-global.js which contain code:

window.__karma__.start = (function(originalStartFn){
return function(){
   var args = arguments
   $(function(){
          originalStartFn.apply(null, args);
    });
};
}(window.__karma__.start));

Thanks!

@ghost
Copy link

ghost commented Aug 26, 2016

I have this issue, the solution @maksimr posted doesn't work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants