-
-
Notifications
You must be signed in to change notification settings - Fork 701
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
expect(array).to.deep.include({...}) does not apply deep equality recursively #390
Comments
@bitliner thanks for the issue. Could you please give a more concrete example? What is expect([ {foo: {bar:true} } ]).to.deep.include({ foo: {bar:true} }); |
Sorry, my fault.
Using |
Hmm. Looks like you've probably got two different Date objects that you're testing against. Despite the Date's having the same value, they wont have the same reference, and so do not equal. I guess |
I am having a similar issue: #399 I have also tried using |
How do you do this with assert style? there is no |
This doesn't work for nested arrays either. I need to test whether an associative array contains some entry but the following fails: [['a','A'],['b','B']].should.deep.contain(['a','A'])
-->
AssertionError: expected [ [ 'a', 'A' ], [ 'b', 'B' ] ] to include [ 'a', 'A' ] What I find surprising is, that it works as expected using [['a','A'],['b','B']].should.include.deep.members([['a','A']]) |
Hello guys, thanks for your reports! 😄 @bnord01 Currently we don't even differentiate This looks like a very easy fix. We could just change this line on assertions.js L214. If this condition was written as Hi, @felixfbecker you could just use What is your opinion about it, @keithamus, should we add support for a |
@lucasfcosta imo the default should be to search by object reference. I would then expect |
@lucasfcosta that sounds not like desirable behavior to me. Indeed I was surprised that |
@felixfbecker thanks for your feedback, I agree with you. Let's just wait for a third opinion on this just to make sure this should really be done. 😃 @bnord01 Thanks for sharing your thoughts. I'm not sure that warning would be a good idea, but we can talk about that and come to an agreement. When it comes to the deep flag I totally agree with you both about the |
@lucasfcosta I just ran into this issue as well. It was my hope that |
Just ran into this issue when testing errors. expect(validationError).to.deep.contain({
name: 'ValidationError',
errors: {
subject: { kind: 'required' },
content: { kind: 'required' },
},
}); Basically, I want to test that a subset of the properties match deeply, since I cannot test all the properties, therefore I can't use |
Another basic failure case for "include" is:
Ultimately, it's using an '===' on the value assertion. I've tried various "deep" flags and other tricks ("contain", "keys", "members") but to no avail. How can I make such a simple assertion (without using "property" as I don't want the assertion subject to change - which is why I'm using "include" in the first place). |
Whoops forgot to close this issue. Fixed via #761, will be released in 4.x (alpha release will be available on npm soon). |
So what would be the proper syntax to solve this use case ? |
@leo-thumbtack In Chai v4 (currently available via |
What about assert style? |
@felixfbecker |
Thanks |
This fails with assert on chai v4.1.0:
This is bug? How i can test if array include object with some specified properties? upd: can be fixed with chai-subset plugin. Code is something like:
|
@deksden |
Hi, I'd like to ask about if with function could be test this condition:
Thanks. |
Hi @djom20, I think you could try to use a matcher or search for a plugin which would allow you to do that easily in a single assertion. As a last resort you could also do: const checkItemsInclude = (arr, str) => arr.some(i => i.includes(str));
expect(checkItemsInclude(yourArray, 'end')).to.be.equal(true); If you're checking for multiple items in the same array you can make that function curried: const arrayIncludeMatcher = arr => str => arr.some(i => i.includes(str));
const arrayIncludes = arrayIncludeMatcher(yourArray);
expect(arrayIncludes('something')).to.be.equal(true);
expect(arrayIncludes('something wrong')).to.be.equal(false); |
Thanks, it's working great now. |
As the title says,
if I run
expect(array).to.deep.include(obj)
I would expect to apply deep equality to each of the property ofobj
.But it does not behave like this, is it a bug?
The text was updated successfully, but these errors were encountered: