-
-
Notifications
You must be signed in to change notification settings - Fork 700
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
Overwrite method default _super does not throw #467
Comments
Hey @wbyoung thanks for the issue.
If this is not working for you, I'd guess that maybe you're loading your plugin before other ones? Your plugin should be loaded last if you're doing this kind of logic - that way |
@keithamus thanks for the response. I may not have been completely clear. I understand the logic that's going on in the Imagine you're creating a plugin that you wanted to be compatible with another commonly used plugin (for instance, I reworked my example from above to use We'll have to delve into the theoretical a little to get to the point. If You could install either one before the other and they would work perfectly together. Both would call through to The main problem, though, is that this would pass: var array = [];
array.should.have.callCount(5); Put another way, in may other programming languages, |
One last thought: I believe plugins could implement something to handle this scenario themselves using (semi-private) understanding of Chai's var overwriteOrAddMethod = function(name, fn) {
if (typeof Assertion.prototype[name] === 'function') {
Assertion.overwriteMethod(name, fn);
}
else {
var _superError = function() { throw new Error('Method \'' + name + '\' cannot be used in this context'); };
Assertion.addMethod(name, fn(_superError));
}
}; I guess the real questions are:
|
Ah, I see now. You make a good point. The default behaviour should probably throw, because as you say there is a chance of silently passing on methods that don't exist. PR welcome, but please make the PR against the |
This is fixed in the 4.x.x branch by 2f4cd16. |
👍 thanks @berkerpeksag |
It appears that this is intentional, but it seems that the following plugin:
Should work as so:
The goal here would be to make a plugin that respects other plugins that may define a
callCount
method. I just wanted to check to see if this was the intended behavior of Chai. If it is, is there another way to achieve this type of result?The text was updated successfully, but these errors were encountered: