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 #1403

Open
astoilkov opened this issue May 14, 2015 · 9 comments
Open

Tests start executing before page is loaded #1403

astoilkov opened this issue May 14, 2015 · 9 comments
Labels

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();
    });
  };
}

Look at the discussion about the issue here

@maksimr
Copy link
Contributor

maksimr commented May 14, 2015

Guys should we wait event DOMContentLoaded or load before starting tests?

\cc @karma-runner/contributors

@madmax25
Copy link

Yes please :-) 👍

@sukrosono
Copy link

Yes please

@wiwiwa
Copy link

wiwiwa commented May 10, 2017

+1

Or karma can be configured to not start automatically.

@awyl
Copy link

awyl commented May 11, 2017

+1

2 similar comments
@ttakahashi2013
Copy link

+1

@raphaelchaib
Copy link

+1

@johnjbarton
Copy link
Contributor

Have you tried to add something like

beforeAll((done) => {
   document.addEventListener("DOMContentLoaded", function(event) {
    console.log("DOM fully loaded and parsed");
    done();
  });
});

@johnjbarton
Copy link
Contributor

Also: if you are using an asynchronous framework like angular, then you need to schedule your tests after the framework initializes, which of course is framework dependent (not DOM load dependent really).

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

No branches or pull requests

9 participants