Commit 8c7d533f 8c7d533fb27dfa66f2c51906bd73d28d80c7494c by Nicolas Perriault

refs #369 - fixing asserts not performed on wait timeout

1 parent edfade4b
......@@ -1765,8 +1765,8 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
self.waitDone();
if (!condition) {
self.log("Casper.waitFor() timeout", "warning");
self.emit('waitFor.timeout');
var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout;
self.emit('waitFor.timeout', timeout, onWaitTimeout);
if (!utils.isFunction(onWaitTimeout)) {
throw new CasperError('Invalid timeout function, exiting.');
}
......
......@@ -143,7 +143,17 @@ var Tester = function Tester(casper, options) {
// casper events
this.casper.on('error', function onCasperError(msg, backtrace) {
this.test.fail(msg, {
type: 'error',
doThrow: false,
values: {
stack: backtrace
}
});
});
this.casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
this.warn(f('wait timeout of %dms reached', timeout));
});
function errorHandler(error, backtrace) {
......@@ -186,10 +196,6 @@ var Tester = function Tester(casper, options) {
return;
}
// onRunComplete
this.casper.options.onRunComplete = function test_onRunComplete(casper) {
};
// specific timeout callbacks
this.casper.options.onStepTimeout = function test_onStepTimeout(timeout, step) {
throw new TimedOutError(f("Step timeout occured at step %s (%dms)", step, timeout));
......@@ -235,11 +241,12 @@ Tester.prototype.assertTrue = function assert(subject, message, context) {
standard: "Subject is strictly true",
message: message,
file: this.currentTestFile,
doThrow: true,
values: {
subject: utils.getPropertyPath(context, 'values.subject') || subject
}
}, context || {});
if (!result.success) {
if (!result.success && result.doThrow) {
throw new AssertionError(message, result);
}
return this.processAssertionResult(result);
......@@ -970,13 +977,15 @@ Tester.prototype.exec = function exec(file) {
* Adds a failed test entry to the stack.
*
* @param String message
* @param Object Failure context (optional)
*/
Tester.prototype.fail = function fail(message) {
Tester.prototype.fail = function fail(message, context) {
"use strict";
return this.assert(false, message, {
context = context || {};
return this.assert(false, message, utils.mergeObjects({
type: "fail",
standard: "explicit call to fail()"
});
}, context));
};
/**
......