debitoor / chai-subset

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

not matching fields - the actual value and the expected value are printed very far from each other #70

Open piotr-s-brainhub opened 6 years ago

piotr-s-brainhub commented 6 years ago

OS: Mac OS X 10.12.6 Node.js: 8.9.4 chai: 3.5.0 chai-subset: 1.6.0 mocha: 3.5.3

I have the following test:

const chai = require('chai');
const chaiSubset = require('chai-subset');

chai.use(chaiSubset);

const { expect } = chai;

const actual = {
  foo1: 'bar-1',
  foo2: 'bar-2',
  foo3: 'bar-3',
  foo4: 'bar-4',
  foo5: 'bar-5',
  foo6: 'bar-6',
  foo7: 'bar-7',
  foo8: 'bar-8',
  foo9: 'bar-9',
};

describe('', () => {
  it('', () => {
    expect(actual).to.containSubset({
      foo5: 'some other value',
    });
  });
});

The actual output:

screen shot 2018-02-27 at 19 44 39

I would like the following output:

       {
      -  "foo5": "bar-5"
      +  "foo5": "some other value"
       }

In case of nested objects it should show the full path to a non-matching fields so e.g.,

       {
         "foo": {
           -  "foo5": "bar-5"
           +  "foo5": "some other value"
         },
         "bar": {
           -  "foo5": "bar-5"
           +  "foo5": "some other value"
         },
         - "baz": "actual value",
         + "baz": "expected value",
         + "lorem": "a field which should exist but does not exist"
       }
Ryman commented 1 year ago

Edit: The answer is yes:

chai.config.showDiff = true
chai.config.truncateThreshold = 0

Relevant code: https://github.com/debitoor/chai-subset/blob/master/lib/chai-subset.js#LL18C31-L18C39

Old question: Is there an option to enable this diff, we're using the same version of chai-subset but with chai 4.3 and I only see the following message:

expected { Object (foo1, foo2, ...) } to contain subset { foo5: some other value }

Currently we're using jest-diff to generate the diff message but it's also really noisy for some of our uses case so I'd love if we could just have a diff of the subset expectations instead.