Skip to content

Instantly share code, notes, and snippets.

@leegee
Created January 27, 2016 15:33
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 leegee/300de2ee6112d5aec167 to your computer and use it in GitHub Desktop.
Save leegee/300de2ee6112d5aec167 to your computer and use it in GitHub Desktop.
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