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

Include object in array fails with 4.1.2 #1046

Closed
felixbuenemann opened this issue Sep 10, 2017 · 2 comments
Closed

Include object in array fails with 4.1.2 #1046

felixbuenemann opened this issue Sep 10, 2017 · 2 comments

Comments

@felixbuenemann
Copy link

felixbuenemann commented Sep 10, 2017

The following code fails with chai 4.1.2, but works fine with 3.5.0:

var expect = require('chai').expect;
var items = [ { id: 1 }, { id: 3 } ];
expect(items).to.include({ id: 1 });
// AssertionError: expected [ { id: 1 }, { id: 3 } ] to include { id: 1 }

Node version: v8.4.0
Package versions:

chai-test@1.0.0
└─┬ chai@4.1.2
  ├── assertion-error@1.0.2
  ├── check-error@1.0.2
  ├─┬ deep-eql@3.0.1
  │ └── type-detect@4.0.3 deduped
  ├── get-func-name@2.0.0
  ├── pathval@1.1.0
  └── type-detect@4.0.3
@felixbuenemann
Copy link
Author

This problem exists since chai@4.0.0-canary.1, last working version is 3.5.0.

@keithamus
Copy link
Member

Hi @felixbuenemann thanks for the issue.

This is a known breaking change for 4.0.0. Take a look at the release notes which describe this:

You can now use the deep flag for the .include assertion in order to perform a deep equality check to see if something is included on the target.
Previously, .include was using strict equality (===) for non-negated property inclusion, but deep equality for negated property inclusion and array inclusion.
This change causes the .include assertion to always use strict equality unless the deep flag is set.
Please take a look at this comment if you want to know more about it. (Related Issues: #743, PRs: #760, #761)

The solution is to add .deep to your assertion, so expect(items).to.include({ id: 1 }); becomes expect(items).to.deep.include({ id: 1 });.

I'll close this, as we're aware of the breaking change, and we've documented it. Let us know if you have any other issues with your migration 🙂

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