question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests start executing before page is loaded

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
maksimrcommented, May 14, 2015

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

\cc @karma-runner/contributors

1reaction
johnjbartoncommented, Jan 17, 2018

Have you tried to add something like

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

github_iconTop Results From Across the Web

How to Wait until page is fully loaded - Stack Overflow
I've been using excessively long wait periods but would like the test to run faster. let targeturl = 'http:\\something.com' let longwait = 2500 ......
Read more >
Load Testing Best Practices | LoadNinja
After running your load tests, the first obvious step is to identify any problem areas & take the next best steps to improving...
Read more >
Catalog of Events - Cypress Documentation
Fires as the page begins to load, but before any of your applications JavaScript has executed. This fires at the exact same time...
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
The setUp() and tearDown() methods allow you to define instructions that will be executed before and after each test method. They are covered...
Read more >
Detect if a Document Has Loaded with JavaScript
I thought the best way to avoid these problems was to ensure the document had loaded before each test run -- that way...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found