debitoor / chai-subset

"containSubset" object properties matcher for Chai
http://chaijs.com/plugins/chai-subset/
MIT License
82 stars 20 forks source link

Use Chai to perform diffs #4

Closed RobertHerhold closed 9 years ago

RobertHerhold commented 9 years ago

This chai-subset plugin has its own "comparison" implementation that is shown when an assertion does not match. In my test, the output looks like:

  11 passing (20ms)
  1 failing

  1) plain object should pass for smaller object:
     AssertionError: expected
{
    "a": "b",
    "c": "d"
}
to contain subset 
{ a: 'ba' }

Yes, the spacing is actually misaligned in the console, but that is not a big deal.

I think this can be improved by letting Chai handle the diff process like it does for its core assertions. Developers can set the Chai config showDiff to either true or false, with true being the default.

Here is what Chai's built-in diff looks like:

  11 passing (16ms)
  1 failing

  1) plain object should pass for smaller object:

      AssertionError: expected { a: 'b', c: 'd' } to contain subset { a: 'ba' }
      + expected - actual

       {
      +  "a": "ba"
      -  "a": "b"
      -  "c": "d"
       }

When delegating the diff process to Chai, the spacing is correctly aligned and you get some neat green text where there should be additions (+) to the object and red text for the opposite case (-).

Please try it out with a failing test case and let me know what you think!

ebdrup commented 9 years ago

Hi @RobertHerhold Thanks a lot for this contribution. We're doing open open source. The extra "open" in there means:

Open Open Source: individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

Inspired by io.js: http://www.pubnub.com/blog/node-js-vs-io-js-creating-open-open-source-contributions/#sthash.sjyGZ4ri.dpuf

There is also a nice video about why here: http://www.pubnub.com/blog/node-js-vs-io-js-creating-open-open-source-contributions/

You should still do pull requests, so we can discuss before merging. But we are giving you the right to merge.

ebdrup commented 9 years ago

Hmmm, I'm experiencing some issues with giving you access, seems we have to make you part of our org, and that has unwanted implications.

eagleeye commented 9 years ago

Works perfect! Thanks a lot, i'll publish new version soon with updated dev deps