Created
November 16, 2011 16:37
-
-
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.
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
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); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! This is perfect.