-
-
Notifications
You must be signed in to change notification settings - Fork 698
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.not.include(obj) failing with constructors #743
Comments
Hi @GabeMedrash, thanks for the issue! I think you are right and this is linked to #390. I think that we should fix this by adding the possibility of using the What do you think @meeber and @keithamus (anyone else is also welcome to share your thoughts on this, I'm just tagging these two guys so they can see it 😄 )? In any case, implementing that should be reasonably easy, all we've gotta do is add a check before running |
@GabeMedrash As a workaround I recommend using expect(arr).to.include.members([instance1]);
expect(arr).to.not.include.members([instance2]); @lucasfcosta The behavior of |
Cool thanks so much, @lucasfcosta and @meeber. I can confirm that For what it's worth, @lucasfcosta, your proposed change to do an initial check if Thanks again. |
Looked through the commit history. Here's what happened:
Based on the above, I think the current functionality is a bug. After all, the This makes me feel a lot more comfortable about changing the current behavior. As I said before, the current functionality has always felt a bit strange to me, but I hadn't looked into it deeply so I just kinda assumed it had been designed this way on purpose. I propose the following (which I believe is in line with what has already been suggested):
|
Agreed with @meeber. Sounds like a straightforward fix and falls inline with other assertions. |
I also agree with @meeber. |
I'll likely knock this out over the weekend unless someone else chimes in wanting to do it. |
Just noting that I was half-wrong about this statement:
It only uses Therefore, I'm changing the plan of action from:
To:
|
I ran into a problem while refactoring This is with the current version of Chai, prior to my changes: expect({a: 1, b: 2}).to.not.include({c: 3}); // Passes
expect({a: 1, b: 2}).to.not.have.property('c', 3); // Error: { a: 1, b: 2 } has no property 'c' In my opinion, there are three options:
I feel pretty strongly that the third option is the most intuitive. To me, However, this argument was made before in #16, and was ultimately rejected. @keithamus @lucasfcosta Your thoughts? |
@meeber Well, IMO the first one is the most correct. However, if that second assertion was If we used option Let me know if you need any help. I'm also open to talk about what is the optimal choice here so we can all agree about what would be better 😄 |
@lucasfcosta Whoops, screwed up my example. I just corrected my post. I meant |
@meeber Makes sense, I even wondered how we were going to get a variable's name to do this check 😆 However, thinking that when we've got two arguments and the If anyone disagrees you're welcome to share your point of view 😄 |
@lucasfcosta Yes, it's exactly like the issue we ran into with the |
Ran into yet another problem. Applying the
This is highly problematic in terms of enabling deep equality support on the At this point I'm inclined to say that |
@meeber I'm afraid I didn't understand your problem with the deep flag, sorry 😓 Would you mind explaining it with an example or showing me some code? IMO the behavior we have agreed upon before seems to be the most correct, but if we really can't do this without much trouble maybe we should make the current behavior more explicit on the DocStrings. |
The problem I'm having with the The var deepObj = {
green: { tea: 'matcha' }
, teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
};
expect(deepObj).to.have.deep.property('green.tea', 'matcha');
expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha'); It hurts my heart that the We can still make Edit: We can still also merge #744 if we believe that to be the desired behavior for |
@meeber makes sense to me now, thanks for the explanation. Great job buddy (and thanks again for taking your time to explain the details to me 😄 ) |
@lucasfcosta I thought about it more this morning and have an idea for a different approach: #745 |
This issue just made me feel confused for a couple of hours. Could you perhaps change the documentation to make it more clear what include does; more specifically perhaps add examples to clarify that |
@lukashoegh I'm working on overhauling the |
@lucasfcosta @keithamus Big changes ready for review. I submitted these changes in the form of 5 separate PRs with 1 commit each that build upon one another; I'm interested to know if this approach is easier/harder/identical from a reviewer's perspective than a single PR with 5 commits. The PRs in order are: #744, #757, #758, #760, #761 What I was trying to achieve with these PRs is best summarized by this comment. Basically trying to make the Summary of breaking changes across these PRs:
In addition to these breaking changes, |
Reviewed and agree with the changes. Although it changes lots for our users, its a useful change and makes @meeber - I will say that, because of the impact of this change, we should also consider releasing a tool to help migrate code from <4 to 4.0 - using something like jscodeshift to automatically change our user's code to switch to |
@keithamus Thanks for reviewing! Just out of curiosity, did it help having the commits split between multiple PRs, even though only the last one is actually needed? I'll take a look at Regarding 4.x: This was the last major change I was working on. I know we still have the |
In this instance because they were multiple discrete changes it makes sense for individual PRs. So 👍
One of those, not sure which. Just wanted to spur a conversation about it
I need to get some time to really push on deep-eql and ideally I'd like loupe too, but we can let it slide to concentrate on getting 4.0 out the door. |
@keithamus @meeber Using I think a migration guide with detailed explanation would be enough, I'd love to help writing it. We can also inspire ourselves into the |
This may be linked to #390, but I'm not sure so reporting this separately:
Environment:
Test case:
As a workaround, I can change the constructor to:
and
expect(arr).to.not.include(instance2)
will work fine.The text was updated successfully, but these errors were encountered: