Skip to content
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 it be possible to overwrite a chainable method? #215

Closed
hazeledmands opened this issue Nov 26, 2013 · 3 comments
Closed

Should it be possible to overwrite a chainable method? #215

hazeledmands opened this issue Nov 26, 2013 · 3 comments

Comments

@hazeledmands
Copy link

I was trying to add some custom behavior to the length assertion, when I noticed that overwriteMethod doesn't seem work on chainable methods.

Is this by design? Am I missing something fundamental here? Or should there be code in the chai plugin API to let you do something like this:

Assertion.overwriteChainableMethod('length', function(_super, _superChain) {
  if( /* something */ ) {
    return {
      method: function() { /* custom assertion */ },
      chainingBehavior: function() { /* custom chaining behavior */ }
    };
  } else {
    return {
      method: _super,
      chainingBehavior: _superChain
    }
  }
});

Feel free to tell me to write a pull request, just wondering if it's worth my time. Anyway, thanks very much for this library; it's pretty awesome. :)

@logicalparadox
Copy link
Member

This is currently not implemented but I think it would be a good idea. Can it look like this:

Assertion.overwriteChainableMethod('length', {
  method: function(_super) {
    return function() {};
  },
  chain: function(_super) {
    return function() {};
  }
});

Might be difficult to separate the chain _super from the method _super with the current way things are done. Open to ideas or PRs...

@hazeledmands
Copy link
Author

Hoo boy. I'm beginning to see why this is difficult. This pull request is going to involve some pretty terrifying code, but at least it'll be a jumping-off point for discussion, I hope.

@logicalparadox
Copy link
Member

Looking forward to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants