Skip to content

Commit

Permalink
test: set up custom asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
amoncaldas committed Nov 2, 2021
1 parent 14f6ffd commit 63547a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/e2e/custom-assertions/elementCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// For more information on custom assertions see:
// http://nightwatchjs.org/guide#writing-custom-assertions

exports.assertion = function (selector, count) {
exports.assertion = function elementCount(selector, count) {
this.message = 'Testing if element <' + selector + '> has count: ' + count
this.expected = count
this.pass = function (val) {
Expand Down
27 changes: 27 additions & 0 deletions tests/e2e/custom-assertions/elementCountAbove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// A custom Nightwatch assertion.
// The assertion name is the filename.
// Example usage:
//
// browser.assert.elementCount(selector, count)
//
// For more information on custom assertions see:
// http://nightwatchjs.org/guide#writing-custom-assertions

exports.assertion = function elementCountAbove (selector, count) {
this.message = 'Testing if element <' + selector + '> has count above: ' + count
this.expected = count
this.pass = function (val) {
return val > this.expected
}
this.value = function (res) {
return res.value
}
this.command = function (cb) {
var self = this
return this.api.execute(function (selector) {
return document.querySelectorAll(selector).length
}, [selector], function (res) {
cb.call(self, res)
})
}
}

0 comments on commit 63547a9

Please sign in to comment.