Skip to content

Commit

Permalink
Add tests & docs for ifExists/ifVisible
Browse files Browse the repository at this point in the history
  • Loading branch information
aexaey committed Mar 8, 2017
1 parent f9e8429 commit 97bd931
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,18 @@ Get the URL of the current page.

Determines if a selector is visible, or not, on the page. Returns a boolean.

#### .ifVisible(selector, fn)

Determines if a selector is visible, or not, on the page. Runs a function if it is.

#### .exists(selector)

Determines if the selector exists, or not, on the page. Returns a boolean.

#### .ifExists(selector, fn)

Determines if the selector exists, or not, on the page. Runs a function if it does.

#### .count(selector)

Counts the number of `selector` on the page. Returns a number.
Expand Down
64 changes: 64 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,38 @@ function evaluation(bool) {
.be.false();
});

it('should verify an element exists and execute callback', function() {
var horseman = new Horseman({
timeout: defaultTimeout,
injectJquery: bool
});
var str = 'yo';
return horseman
.open(serverUrl)
.ifExists('a', function(){
return str;
})
.close()
.should.eventually
.equal(str);
});

it('should verify an element does not exists and not execute callback', function() {
var horseman = new Horseman({
timeout: defaultTimeout,
injectJquery: bool
});
var str = 'yo';
return horseman
.open(serverUrl)
.ifExists('yeti', function(){
return str;
})
.close()
.should.eventually
.be.undefined();
});

it('should count the number of selectors', function() {
var horseman = new Horseman({
timeout: defaultTimeout,
Expand Down Expand Up @@ -575,6 +607,38 @@ function evaluation(bool) {
.be.false();
});

it('should determine that an element is visible and execute callback', function() {
var horseman = new Horseman({
timeout: defaultTimeout,
injectJquery: bool
});
var str = 'yo';
return horseman
.open(serverUrl)
.ifVisible('a', function(){
return str;
})
.close()
.should.eventually
.equal(str);
});

it('should determine that an element is not visible and not execute callback', function() {
var horseman = new Horseman({
timeout: defaultTimeout,
injectJquery: bool
});
var str = 'yo';
return horseman
.open(serverUrl)
.ifVisible('.login-popup', function(){
return str;
})
.close()
.should.eventually
.be.undefined();
});

it('should evaluate javascript', function() {
var horseman = new Horseman({
timeout: defaultTimeout,
Expand Down

0 comments on commit 97bd931

Please sign in to comment.