Skip to content

Commit

Permalink
Fixed #1835 - issue with loading non js custom assertion files
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Aug 15, 2018
1 parent 34e3b60 commit b3e1e18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/api-loader/assertion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const util = require('util');
const EventEmitter = require('events');
const isObject = require('../util/utils.js').isObject;
const Utils = require('../util/utils.js');
const NightwatchAssertion = require('../core/assertion.js');
const BaseCommandLoader = require('./_base-loader.js');

Expand Down Expand Up @@ -41,7 +41,7 @@ class AssertionLoader extends BaseCommandLoader {
}

validateModuleDefinition() {
if (!(isObject(this.module) && this.module.assertion)) {
if (!(Utils.isObject(this.module) && this.module.assertion)) {
throw new Error('The assertion module needs to contain an .assertion() method');
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ class AssertionLoader extends BaseCommandLoader {
}

runAssertion(passed, value, calleeFn, message) {
let expected = typeof this.instance.expected == 'function' ? this.instance.expected() : this.instance.expected;
let expected = Utils.isFunction(this.instance.expected) ? this.instance.expected() : this.instance.expected;

this.assertion = NightwatchAssertion.create(passed, {expected, actual: value}, calleeFn, message, this.abortOnFailure, this.stackTrace);

Expand All @@ -107,7 +107,7 @@ class AssertionLoader extends BaseCommandLoader {
let value;
let timeSpent = new Date().getTime() - this.startTime;

if (typeof this.instance.failure == 'function' && this.instance.failure.call(this.instance, result)) {
if (Utils.isFunction(this.instance.failure) && this.instance.failure.call(this.instance, result)) {
passed = false;
value = null;
} else {
Expand Down Expand Up @@ -150,18 +150,20 @@ class AssertionLoader extends BaseCommandLoader {
}

createWrapper(abortOnFailure) {
this.validateModuleDefinition();
if (this.module) {
this.validateModuleDefinition();

let moduleDefinition = this.module.assertion;
this.abortOnFailure = abortOnFailure;
let assertion = this;
let moduleDefinition = this.module.assertion;
this.abortOnFailure = abortOnFailure;
let assertion = this;

this.commandFn = function commandFn(...args) {
assertion.stackTrace = commandFn.stackTrace;
assertion.createInstance(moduleDefinition, args);
this.commandFn = function commandFn(...args) {
assertion.stackTrace = commandFn.stackTrace;
assertion.createInstance(moduleDefinition, args);

return assertion.executeCommand();
};
return assertion.executeCommand();
};
}

return this;
}
Expand Down
Empty file added test/extra/assertions/.dotrc
Empty file.

0 comments on commit b3e1e18

Please sign in to comment.