Created
December 5, 2014 13:45
-
-
Save trodrigues/4aead044ab1a81f1cf02 to your computer and use it in GitHub Desktop.
Revisions
-
trodrigues created this gist
Dec 5, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ // use with https://www.npmjs.org/package/deep-diff toEqualObj: function () { var KINDS = { 'N': 'newly added property/element', 'D': 'property/element was deleted', 'E': 'property/element was edited', 'A': 'change occurred within an array' }; function formatDiff(objdiff) { return objdiff.map(function (diff) { return '\t'+diff.kind +' at '+ diff.path.join('.') +'\n'+ '\t'+diff.actual +' should be '+ diff.expected; }).join('\n\n'); } return { compare: function (actual, expected) { var objdiff = (deepDiff(expected, actual) || []).map(function (diff) { return { kind: KINDS[diff.kind], path: diff.path, expected: diff.lhs, actual: diff.rhs }; }); return { pass : objdiff.length === 0, message : 'Expected object not to have differences\n\n' + formatDiff(objdiff) }; } }; }