-
-
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
embracing proxies #787
Comments
My first impression is that it sounds cool in theory but in practice it opens the door too wide for mistakes and unexpected behavior without adding enough benefit over I think enabling cool shortcuts like |
I've seen that in v4 proxies are used to protect from such problems to occur, |
|
The use of proxy in 4.x is for defensive purposes only. Acting as a catch-all property-assertion in the proposed way, I think there's too much room for accidents and misinterpretation. let gasTank = {
empty: true,
};
gasTank.should.be.empty; Did the developer mean to check the domain-specific concept of a tank of gas being empty, or did they mean to use Chai's This becomes even more problematic when you consider how the behavior changes between environments that support proxies and those that don't. let element = { visible: true }
element.should.be.visible In proxy-supported environments, this would perform an assertion to check if Due to the risk, I think this type of change is better suited to a plugin as opposed to Chai's default behavior. I would recommend that such a plugin be configured to only work in environments that support proxies. Restricting the behavior to |
Could such plugin (which monkey patches Chai) be exposed at chaijs.com/plugins ? |
@yairper I suspect it's possible to write a normal plugin (http://chaijs.com/guide/plugins/) that implements the desired behavior by replacing If it turns out there's really no way to implement this behavior through the plugin system and forking Chai is the only option, then I'm not sure what the best way to advertise it is. @keithamus @lucasfcosta? |
I checked it up, and it could be done using the conventional way, Thanks ! |
@meeber Hmm, I'm not sure this behavior cannot be added to Chai through the plugin system. Regarding the addition of this to the Core I totally agree with @meeber. His great explanation covers every thought I've had about it. I'd rather keep this in a separate plugin and avoid adding the possibility of writing contradictory assertions. |
Hi,
We could start enjoying the power of proxies to create even better DSL.
Examples:
WDYT?
The text was updated successfully, but these errors were encountered: