Skip to content

Instantly share code, notes, and snippets.

@superchris
Created November 12, 2011 01:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save superchris/1359867 to your computer and use it in GitHub Desktop.
Save superchris/1359867 to your computer and use it in GitHub Desktop.
loading templates in jasmine specs
jasmine.Fixtures.prototype.loadTemplate_ = function(template) {
var templateUrl = "/backbone/templates/" + template;
var self = this;
$.ajax({
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
cache: false,
dataType: 'html',
url: templateUrl,
success: function(data) {
$('#' + self.containerId).append(data);
}
});
};
function loadTemplate(template) {
jasmine.getFixtures().loadTemplate_(template);
}
jasmine.Fixtures.prototype.loadJson_ = function(jsonFile) {
var jsonUrl = "/spec/javascripts/fixtures/" + jsonFile;
var json = "";
var self = this;
$.ajax({
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
cache: false,
dataType: 'json',
url: jsonUrl,
success: function(data) {
json = data;
}
});
return json;
};
function loadJson(jsonFile) {
return jasmine.getFixtures().loadJson_(jsonFile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment