Jasmine JSON matcher
Comparing large objects with jasmine works great until you get an error, when it dumps the entire object to the console in a completely human unreadable format.
This package adds a
toEqualJson matcher to jasmine that will generate nice
diffs on error. It will tell you which keys differ, and why.
# In your spec helperrequire 'jasmine-json'# In your specsdescribe "something"->it "tests json"->someObject =one: 1two:three: 5four: 4expectsomeObjecttoEqualJsonone: 1two:three: 3four: 4five: 5
It will give you the path of the failure:
JSON is not equal: two: actual: has keys ["four","three"] expected: has keys ["five","four","three"]
If there are several errors, it will report all of them:
it "tests json"->someObject =two:three:four:five: 4six: 5seven: 6expectsomeObjecttoEqualJsontwo:three:four:five: 5six: 6seven: 7
JSON is not equal: two.three.four.five: actual: 4 expected: 5 two.three.four.six: actual: 5 expected: 6 two.three.four.seven: actual: 6 expected: 7