Commit 66031b03 66031b0305e5435d8e960037e2aba4ad37f416b4 by Julien Muetton

Add `casper.thenSkip()`, `casper.thenSkipIf()`...

... and `casper.thenSkipUnless()`
1 parent 6dd97c9c
......@@ -1614,6 +1614,55 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) {
};
/**
* Skip `nb` tests.
*
* @param Integer nb number of tests to skip
* @param String message message to display
*/
Casper.prototype.thenSkip = function (nb, message) {
return this.then(function () {
this.test.skip(nb, message);
});
};
/**
* Skip `nb` tests if condition is true.
*
* @param Mixed condition number of tests to skip
* @param Integer nb number of tests to skip
* @param String message message to display
*/
Casper.prototype.thenSkipIf = function (condition, nb, message) {
return this.then(function () {
if (utils.isFunction(condition)) {
condition = condition();
}
if (utils.isTruthy(condition)) {
this.test.skip(nb, message);
}
});
};
/**
* Skip `nb` tests if condition is true.
*
* @param Mixed condition number of tests to skip
* @param Integer nb number of tests to skip
* @param String message message to display
*/
Casper.prototype.thenSkipUnless = function (condition, nb, message) {
return this.then(function () {
if (utils.isFunction(condition)) {
condition = condition();
}
if (utils.isFalsy(condition)) {
this.test.skip(nb, message);
}
});
};
/**
* Adds a new navigation step for opening and evaluate an expression
* against the DOM retrieved from the provided location.
*
......
......@@ -61,3 +61,78 @@ casper.test.begin('Skip does not polluate next suite', 1, function(test) {
});
});
casper.test.begin('Casper.thenSkip', 2, function(test) {
casper.
thenSkip(1).
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Casper.thenSkipIf', 5, function(test) {
casper.
thenSkipIf(true, 1, "Skip if with function").
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
}).
thenSkipIf(function () {
return true;
}, 1, "Skip if with function").
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
}).
thenSkipIf(function () {
return false;
}, 1, "Do not skip if with function").
then(function () {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Casper.thenSkipUnless', 5, function(test) {
casper.
thenSkipUnless(false, 1, "Skip unless with function").
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
}).
thenSkipUnless(function () {
return false;
}, 1, "Skip unless with function").
then(function () {
test.fail("This test should be skipped.");
}).
then(function () {
test.pass("This test should be executed.");
}).
thenSkipUnless(function () {
return true;
}, 1, "Do not skip unless with function").
then(function () {
test.pass("This test should be executed.");
});
casper.run(function() {
test.done();
});
});
......