Created
January 27, 2016 15:33
-
-
Save leegee/300de2ee6112d5aec167 to your computer and use it in GitHub Desktop.
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
jasmine.addMatchers( jasmine.XXX.customMatchers ); | |
// This must load before any tests are run. | |
jasmine.XXX.customMatchers = { | |
toEqualNice: function(util, customEqualityTesters) { | |
return { | |
compare: function(actual, expected) { | |
if (expected === undefined) { | |
expected = ''; | |
} | |
var result = {}; | |
result.pass = util.equals(actual, expected, customEqualityTesters); | |
if (! result.pass) { | |
result.message = 'Expected:\n\t'+ JSON.stringify(expected, null, '\t') + '\nReceived:\n\t' + JSON.stringify(actual, null, '\t'); | |
result.message += '\nDiff:\n\n'; | |
var diff = JsDiff.diffLines( | |
JSON.stringify(expected, null, ' '), | |
JSON.stringify(actual, null, ' ') | |
); | |
diff.forEach(function(part){ | |
var marker = part.added ? '+++ ' : | |
part.removed ? '--- ' : ' '; | |
result.message += marker + part.value + '\n' | |
}); | |
} | |
return result; | |
} | |
}; | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment