Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikelovesrobots/3171830 to your computer and use it in GitHub Desktop.
Save mikelovesrobots/3171830 to your computer and use it in GitHub Desktop.
Jasmine pretty print monkeypatch for sane test failure messages (dump in spec/javascripts/helpers)
jasmine.PrettyPrinter.prototype.iterateObject = (obj, fn) ->
for own property, _ of obj
if property == '__Jasmine_been_here_before__'
continue
fn(property, if obj.__lookupGetter__ then (obj.__lookupGetter__(property) != jasmine.undefined && obj.__lookupGetter__(property) != null) else false)
jasmine.StringPrettyPrinter::originalEmitObject = jasmine.StringPrettyPrinter::emitObject
jasmine.StringPrettyPrinter::emitObject = (obj) ->
if obj instanceof jQuery
@emitJQuery obj
else
@append obj.className + '(' if obj.className != 'Object'
@originalEmitObject(obj)
@append ')' if obj.className != 'Object'
jasmine.StringPrettyPrinter::emitJQuery = (obj) ->
@append("$(")
elements = []
for i in [0...obj.length]
elements.push obj[i].outerHTML.replace(/>[\s\S]*</, '>...<')
@append elements.join(', ')
@append(")")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment