-
Notifications
You must be signed in to change notification settings - Fork 69
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
Overriding '.be' causes incorrect usage to be silently ignored #39
Comments
@eventualbuddha [ 'to', 'be', 'been'
, 'is', 'and', 'has', 'have'
, 'with', 'that', 'at'
, 'of', 'same' ].forEach(function (chain) {
Assertion.addProperty(chain, function () {
return this;
}); So, your code should be corrected and it will start looking like |
@theghostbel yes, that's true. However, my point is that using If you are skeptical that this is a problem, try introducing Chai + chai-jquery on a project with 20+ active committers who are not in the same team or location and who have either zero or very little experience with either. Heck, even experienced Chai users could make that mistake, at least in doing a code review if not in writing it themselves. So the question remains: how do we fix this? My suggestions as in the original post remain the same, but I'm no Chai expert so I'll defer to others on a real fix. |
@eventualbuddha Personally I don't know real fix at the time, but here are jsfiddles which reproduce the issue:
|
Yep, thanks for making the examples, @theghostbel. I think we'll probably end up forking and just removing |
Fixed in 270e8de. |
Thanks, @jfirebaugh. |
Let's say you are new to Chai or you just forget all the matchers and how they work. You might think that this is how you check that something is the same as something else:
Without chai-jquery loaded this throws an error:
TypeError: Property 'be' of object #<Assertion> is not a function
. However, when chai-jquery is loaded and you run this again you will get no exception. This seems to be because of thebe
override that can be called as a function. The trouble is that when the object being asserted against isn't a jQuery object the assertion is simply a no-op.I'm not sure how to fix this. My inclination is to simply remove the
be
override and tell people to usematch
, though that'd obviously break backward compatibility. If there's some way to determine that it is being called in the manner above and to throw an exception that would be best.The text was updated successfully, but these errors were encountered: