New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show diff for keys assertion #264

Merged
merged 1 commit into from May 28, 2014

Conversation

Projects
None yet
2 participants
@cjthompson

cjthompson commented May 28, 2014

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

   [
     "id",
  +  "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.

Chris Thompson

logicalparadox added a commit that referenced this pull request May 28, 2014

Merge pull request #264 from cjthompson/keys_diff
Show diff for keys assertion

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

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@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