-
Notifications
You must be signed in to change notification settings - Fork 124
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
Add .if_exists()/.if_visible() (implements #266) #267
base: master
Are you sure you want to change the base?
Conversation
I'm not sure how I feel about these functions. They feel unnecessary to me. If other people want them I might pull them in. Do you have an opinion @johntitus? Also, the underscores in the name irk me, the do not match any of the other function names. |
Regarding underscores - would this sort of syntax be more palatable? .visible('#foo')
.if(function() {
... i.e. add new |
I would have just made them |
Oh, I see. Cool. I've changed PR to use headlessCamelCase. |
Seems useful but I too hesitate to go too far down this sort of rabbit hole. I lean towards accepting this PR (and thanks for making it @aexaey) if tests are added. |
Thanks @johntitus , I've added tests and bare-bones descriptions to Readme.md. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for contributing. I found some things.
*/ | ||
exports.ifExists = function(selector, fn) { | ||
debug('.ifExists()', selector); | ||
return this.count(selector).then(function(count) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just use the existing .exists()
action rather than re-implementing it.
*/ | ||
exports.ifVisible = function(selector, fn) { | ||
debug('.ifVisible()', selector); | ||
return this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you should utilize the existing .visible()
action.
return this.count(selector).then(function(count) { | ||
if (count > 0) { | ||
return fn(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the indentation consistent, as I am neurotic about that.
debug('.ifExists()', selector); | ||
return this.count(selector).then(function(count) { | ||
if (count > 0) { | ||
return fn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should pass the resolution value of the previous Promise to fn
.
For example
...
.return('foobar')
.ifExists('selectorThatExists', function(res) {
console.log(res); // Should log 'foobar'
})
No description provided.