Show diff for keys assertion #264

merged 1 commit into from May 28, 2014


None yet

2 participants


Use the show diff feature when the keys assertion fails.

Currently, when a keys assertion fails, the output looks like

AssertionError: expected { Object (id, name, ...) } to have keys 'name', and 'id'

That statement makes it impossible to see which keys the source object should or should not have. In this case, Object has more keys than expected, but I don't know what they are.

With this pull request, the output of that same assertion looks like this:

  AssertionError: expected { Object (id, name, ...) } to have keys 'name', and 'id'
  + expected - actual

  +  "name"
  -  "name",
  -  "parent_id",
  -  "type_id"

Now I can see that the parent_id and type_id keys are in the source but shouldn't be.

On lines 988 and 989, the reason for the .sort() call is to make the diff look nicer. Without it, the keys could be in any order and the diff would just show all the keys for both expected and actual.

All mocha tests pass.

@logicalparadox logicalparadox merged commit 67a4f44 into chaijs:master May 28, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
@cjthompson cjthompson deleted the cjthompson:keys_diff branch May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment