Skip to content

Instantly share code, notes, and snippets.

@jorgemanrubia
Created November 16, 2011 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgemanrubia/1370586 to your computer and use it in GitHub Desktop.
Save jorgemanrubia/1370586 to your computer and use it in GitHub Desktop.
Prepare Jasmine's Pretty Printer for working with Backbone. Jasmine has serious problems for printing Backbone objects linked with other objects/Collections (e.g when an expectation fails). It enters in long loops leaving the browser totally frozen.
var addBackboneSupportToJasminePrettyPrinter = function() {
var oldPrettyPrinterFormat = jasmine.PrettyPrinter.prototype.format;
jasmine.PrettyPrinter.prototype.format = function(value) {
var self = this;
if(value instanceof Backbone.Model){
this.emitObject(value.attributes);
}
else if(value instanceof Backbone.Collection){
value.each(function(model) {
self.emitScalar(model.cid);
});
}
else{
oldPrettyPrinterFormat.apply(this, arguments);
}
};
};
@jrreed
Copy link

jrreed commented Jan 15, 2013

Thanks! This is perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment