From 97bd9312de0e1933df8ca7c1ba0466aa647b3743 Mon Sep 17 00:00:00 2001 From: Aex Aey Date: Wed, 8 Mar 2017 00:52:12 +0100 Subject: [PATCH] Add tests & docs for ifExists/ifVisible --- Readme.md | 8 +++++++ test/index.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/Readme.md b/Readme.md index 912d9a4..db2e3b1 100644 --- a/Readme.md +++ b/Readme.md @@ -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. diff --git a/test/index.js b/test/index.js index 3fca99b..e02409a 100644 --- a/test/index.js +++ b/test/index.js @@ -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, @@ -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,