Skip to content
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
Merged

Conversation

cjthompson
Copy link

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.

logicalparadox added a commit that referenced this pull request May 28, 2014
Show diff for keys assertion
@logicalparadox logicalparadox merged commit 67a4f44 into chaijs:master May 28, 2014
@cjthompson cjthompson deleted the keys_diff branch May 28, 2014 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants