-
-
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
should.have.deep.members diff #572
Comments
Hey @qbolec thanks for the issue and welcome to the Chai community 🎉🍰! I'll address each point you have separately:
|
I'll do my best :)
|
To be honest @qbolec we don't have any tests for ensuring that The change will basically be adding If you'd also like to add an example to the docs, showing how one can use |
Hi, One way to test it would be to add following lines here https://github.com/chaijs/chai/blob/master/test/assert.js#L848 :
I'm not sure though, if this style of performing assertions is the correct one.
By the way, why is the Also, I've noticed that in the lib/chai/interface/assert.js library there is My biggest concern though is that I'm not sure if adding |
I've also ran into this problem when creating tests for #515. I was using a try/catch to test the Maybe something like this: global.err = function (fn, msg, callback) {
try {
fn();
throw new chai.AssertionError({ message: 'Expected an error' });
} catch (err) {
if ('string' === typeof msg) {
chai.expect(err.message).to.equal(msg);
} else {
chai.expect(err.message).to.match(msg);
}
if ('function' === typeof callback) callback(err);
}
}; |
I actually forgot about #515. This issue and #515 overlap in a lot of ways (in the sense that #515 would invalidate any work done for this issue). We should probably settle on a good plan of action for what to do here. @lucasfcosta if you have made some progress on #515 then I think we should get @qbolec to hold off on making any changes to this issue before you work is done. @qbolec to address your comments:
This is true. Chai can tweak the given
I feel like the contract is slightly more nuanced than that. Ultimately I'm slowly reaching the conclusion that Chai should probably have diffing capabilities baked in, and present reporters a standardised diff output format. I'm thinking this because right now there are so many small edge cases around existing diffs, and we get so many issues about poor diff reporting from test runners, that it seems like it might be a good idea to centralise diffs within Chai. |
@keithamus Actually I've made just a little progress on #515. I've commented there about a doubt I've had. Can I include into that change the addition of a callback in Thanks for your help! |
@lucasfcosta absolutely! Do you what you need to do to get the tests working 😉 |
@qbolec, I am pining for the missing |
I'm a github noobie, so I'm not sure if my PR is done properly, but you can find the code above. |
It landed in #589 |
🎉 |
I'm new to mocha and chai, so I'm not sure if my issue should be filed against one or the other.
The problem is that I often need to check if two arrays contain same elements up to permutation.
I use
A.should.have.deep.members(B)
for that.Here are my issues:
have
,deep
andmembers
is even "official". The documentation at http://chaijs.com/api/bdd/ formembers
does not present this particular combo, but I guess, it's ok?mocha -R spec
reporter does not show the diff for this assertions, when they fail. Instead, I get rather not helpfulAssertionError: expected [ Array(3) ] to have the same members as [ Array(2) ]
.What would I expect? Something similar to A.sort().should.deep.equal(B.sort()). That is, I'd like to see '-' for each additional member, and '+' for each missing.
The text was updated successfully, but these errors were encountered: