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

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

Open
piotr-s-brainhub opened this issue Feb 27, 2018 · 1 comment

Comments

@piotr-s-brainhub
Copy link

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
Copy link

Ryman commented May 10, 2023

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.

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

No branches or pull requests

2 participants