I'm trying to create a nightwatchJS custom assertion that will check if a file exists. The assertion appears to fire, but nightwatch exits as soon as the assertion command finishes.
I guess I'm not returning control to the nightwatch api, but if thats the case then how can I achieve that?
// filename = doesFileExist.js
exports.assertion = function(fname, msg) {
var fs = require('fs');
this.message = msg + 'FileExists: ' + fname ;
this.expected = true;
this.pass = function(value) {
return value == this.expected;
} ;
this.value = function(result) {
return result;
};
this.command = function(callback) {
return fs.exists(fname, callback);
};
};
and the test case (using nightwatch.json as an example) is ;
this.checkForFile = function() {
browser
.verify.doesFileExist('nightwatch.json', 'test1')
return browser;
};
I know this is an old question, but I found in writing my own custom assertions that you need to return 'this' in your command function. The callback is what sends your value to this.value which is used in the pass function.
So it would look like this