I was stuck on this for hours until I started stepping through the script in the browser and figured out what was happening. As others have already figured out, jasmineEnv.execute() is being called before the tests are getting registered due to the asynchronous nature of the modules being loaded.
I've seen some resolve this issue by moving the call to 'require' into the test. This likely works, but as these individuals have pointed out, this is ugly. I've come up with a creative solution that works great! It works in all three scenarios:
Disclaimer - I haven't tested this with code coverage yet, so it may need a bit more work.
I've seen some resolve this issue by moving the call to 'require' into the test. This likely works, but as these individuals have pointed out, this is ugly. I've come up with a creative solution that works great! It works in all three scenarios:
- Open in Browser
- Run JS Tests
-
Run from Test Explorer
/// <reference path="./../Scripts/libs/require.js" />
requirejs.config({
baseUrl: '../Scripts'
});
var ChutzpahTestsToRun = [
'../Tests/some.test',
'../Tests/another.test'
];
(function () {
var jasmineEnv = jasmine.getEnv();
var runner = jasmineEnv.currentRunner();
var executor = jasmineEnv.execute;
// Check if runner hasn't been executed
// If so, run it
if (!runner.queue.running && runner.queue.index <= 0) {
jasmineEnv.execute = function () {
require(ChutzpahTestsToRun, function () {
jasmineEnv.execute = executor;
jasmineEnv.execute();
});
};
}
})();
By doing this I was able to defer the execution of the Jasmine tests until after all of the test modules were fully loaded.Disclaimer - I haven't tested this with code coverage yet, so it may need a bit more work.