Add .if_exists()/.if_visible() (implements #266)#267
Add .if_exists()/.if_visible() (implements #266)#267aexaey wants to merge 3 commits intojohntitus:masterfrom
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. |
awlayton
left a comment
There was a problem hiding this comment.
Thanks again for contributing. I found some things.
| * @param {function} fn | ||
| */ | ||
| exports.ifExists = function(selector, fn) { | ||
| debug('.ifExists()', selector); |
There was a problem hiding this comment.
You should just use the existing .exists() action rather than re-implementing it.
| * @param {function} fn | ||
| */ | ||
| exports.ifVisible = function(selector, fn) { | ||
| debug('.ifVisible()', selector); |
There was a problem hiding this comment.
Again, you should utilize the existing .visible() action.
| debug('.ifExists()', selector); | ||
| return this.count(selector).then(function(count) { | ||
| if (count > 0) { | ||
| return fn(); |
There was a problem hiding this comment.
Please make the indentation consistent, as I am neurotic about that.
| exports.ifExists = function(selector, fn) { | ||
| debug('.ifExists()', selector); | ||
| return this.count(selector).then(function(count) { | ||
| if (count > 0) { |
There was a problem hiding this comment.
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.