Skip to content

Commit

Permalink
Simplify elementCount custom assertions (#898)
Browse files Browse the repository at this point in the history
* Improve custom Nightwatch assertion comment readability

Standardize capitalization, punctuation
Use common language
Reduce word count

* Clarify elementCount arguments

Before this commit the term `selector` was used for two separate arguments in
two separate scopes. Rename the function passed to the browser so the developer
understands that these are two arguments/two scopes/not the same value.
  • Loading branch information
robwierzbowski authored and yyx990803 committed Nov 21, 2017
1 parent b366b83 commit 5b138f3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions template/test/e2e/custom-assertions/elementCount.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// A custom Nightwatch assertion.
// the name of the method is the filename.
// can be used in tests like this:
// The assertion name is the filename.
// Example usage:
//
// browser.assert.elementCount(selector, count)
//
// for how to write custom assertions see
// For more information on custom assertions see:
// http://nightwatchjs.org/guide#writing-custom-assertions

exports.assertion = function (selector, count) {
this.message = 'Testing if element <' + selector + '> has count: ' + count{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
this.expected = count{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
Expand All @@ -17,8 +18,8 @@ exports.assertion = function (selector, count) {
}
this.command = function (cb) {
var self = this{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
return this.api.execute(function (selector) {
return document.querySelectorAll(selector).length{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
return this.api.execute(function (selectorToCount) {
return document.querySelectorAll(selectorToCount).length{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
}, [selector], function (res) {
cb.call(self, res){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
}){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
Expand Down

0 comments on commit 5b138f3

Please sign in to comment.