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

Issues with deep include and partial matches in associative array #1051

Closed
am11 opened this issue Sep 13, 2017 · 1 comment
Closed

Issues with deep include and partial matches in associative array #1051

am11 opened this issue Sep 13, 2017 · 1 comment

Comments

@am11
Copy link

am11 commented Sep 13, 2017

I am trying to figure out the best way to use .deep and .include. According to #1009 (comment), it seems like latest version of chai.js should work with partial matches.

Here is a similar sample to what I am trying to achieve https://jsfiddle.net/whm06h05/ (setup with latest versions of chai and mocha as of today):

'use strict';

mocha.setup("bdd");
chai.should();

describe('Include tests', () => {
  const array = [];
  array.push({a: 11.1, b: 'blah'});
  array.push({a: 12.1});

  it('should work with deep and exact object graph', () =>
    array.should.deep.include({a: 12.1})); // works
  
  it('should work without deep and exact object graph', () =>
    array.should.include({a: 12.1}));      // doesn't work
  
  it('should work with deep and partial object graph', () =>
    array.should.deep.include({a: 11.1})); // doesn't work
  
  it('should work without deep and partial object graph', () =>
    array.should.include({a: 11.1}));      // doesn't work
});

mocha.run();

With the latest version of chai, is there a way to test partial match; certain member of object in an array matches a value?

@keithamus
Copy link
Member

Hey @am11 thanks for the issue.

At current there is no way to do partial matching. deep should check all properties exhaustively, and so what you're hoping for with that code is not yet implemented. You should subscribe to #644 which is our tracking issue for implementing some kind of partial match.

I'll close this issue, as we should keep #644 as the main tracking issue for this feature.

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