Created
November 30, 2012 00:58
-
-
Save JohnDMathis/4173027 to your computer and use it in GitHub Desktop.
Preload Marionette templates as needed, before any tests are run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Preload Marionette templates as needed, before any tests are run | |
// --------------------------- | |
// jasmine SpecRunner.html: | |
// [cut] | |
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script> | |
<script type="text/javascript"> | |
templateIdsToLoad = []; | |
preloadTemplate=function (id) { | |
templateIdsToLoad.push(id); | |
} | |
preloadTemplates = function (ids) { | |
templateIdsToLoad = ids; | |
} | |
</script> | |
<!-- include spec files here... --> | |
<script type="text/javascript" src="spec/module-spec.js"></script> | |
<!-- include source files here... --> | |
// [cut] | |
<script type="text/javascript"> | |
(function() { | |
var jasmineEnv = jasmine.getEnv(); | |
jasmineEnv.updateInterval = 1000; | |
var htmlReporter = new jasmine.HtmlReporter(); | |
jasmineEnv.addReporter(htmlReporter); | |
jasmineEnv.specFilter = function(spec) { | |
return htmlReporter.specFilter(spec); | |
}; | |
var currentWindowOnload = window.onload; | |
window.onload = function() { | |
if (currentWindowOnload) { | |
currentWindowOnload(); | |
} | |
//execJasmine(); | |
preloadTemplatesAndExecute(); | |
}; | |
function preloadTemplatesAndExecute() { | |
var loadAllTemplates = Backbone.Marionette.TemplateCache.preloadTemplates(templateIdsToLoad, this); | |
$.when(loadAllTemplates).done(execJasmine); | |
} | |
function execJasmine() { | |
jasmineEnv.execute(); | |
} | |
})(); | |
</script> | |
// ---------------------- | |
// module-spec.js: | |
preloadTemplate('user-edit'); | |
preloadTemplate('user-edit-confirm'); | |
preloadTemplate('generic-toggle-item'); | |
describe("preloaded templates are ready", function () { | |
it('user-edit', function () { | |
expect(Backbone.Marionette.TemplateCache.get('#user-edit')).toBeDefined(); | |
}); | |
it('user-edit-confirm', function () { | |
expect(Backbone.Marionette.TemplateCache.get('#user-edit-confirm')).toBeDefined(); | |
}); | |
it('generic-toggle-item', function () { | |
expect(Backbone.Marionette.TemplateCache.get('#generic-toggle-item')).toBeDefined(); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment