Add `casper.thenSkip()`, `casper.thenSkipIf()`...
... and `casper.thenSkipUnless()`
Showing
2 changed files
with
124 additions
and
0 deletions
... | @@ -1614,6 +1614,55 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) { | ... | @@ -1614,6 +1614,55 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) { |
1614 | }; | 1614 | }; |
1615 | 1615 | ||
1616 | /** | 1616 | /** |
1617 | * Skip `nb` tests. | ||
1618 | * | ||
1619 | * @param Integer nb number of tests to skip | ||
1620 | * @param String message message to display | ||
1621 | */ | ||
1622 | Casper.prototype.thenSkip = function (nb, message) { | ||
1623 | return this.then(function () { | ||
1624 | this.test.skip(nb, message); | ||
1625 | }); | ||
1626 | }; | ||
1627 | |||
1628 | /** | ||
1629 | * Skip `nb` tests if condition is true. | ||
1630 | * | ||
1631 | * @param Mixed condition number of tests to skip | ||
1632 | * @param Integer nb number of tests to skip | ||
1633 | * @param String message message to display | ||
1634 | */ | ||
1635 | Casper.prototype.thenSkipIf = function (condition, nb, message) { | ||
1636 | return this.then(function () { | ||
1637 | if (utils.isFunction(condition)) { | ||
1638 | condition = condition(); | ||
1639 | } | ||
1640 | if (utils.isTruthy(condition)) { | ||
1641 | this.test.skip(nb, message); | ||
1642 | } | ||
1643 | }); | ||
1644 | }; | ||
1645 | |||
1646 | /** | ||
1647 | * Skip `nb` tests if condition is true. | ||
1648 | * | ||
1649 | * @param Mixed condition number of tests to skip | ||
1650 | * @param Integer nb number of tests to skip | ||
1651 | * @param String message message to display | ||
1652 | */ | ||
1653 | Casper.prototype.thenSkipUnless = function (condition, nb, message) { | ||
1654 | return this.then(function () { | ||
1655 | if (utils.isFunction(condition)) { | ||
1656 | condition = condition(); | ||
1657 | } | ||
1658 | if (utils.isFalsy(condition)) { | ||
1659 | this.test.skip(nb, message); | ||
1660 | } | ||
1661 | }); | ||
1662 | }; | ||
1663 | |||
1664 | |||
1665 | /** | ||
1617 | * Adds a new navigation step for opening and evaluate an expression | 1666 | * Adds a new navigation step for opening and evaluate an expression |
1618 | * against the DOM retrieved from the provided location. | 1667 | * against the DOM retrieved from the provided location. |
1619 | * | 1668 | * | ... | ... |
... | @@ -61,3 +61,78 @@ casper.test.begin('Skip does not polluate next suite', 1, function(test) { | ... | @@ -61,3 +61,78 @@ casper.test.begin('Skip does not polluate next suite', 1, function(test) { |
61 | }); | 61 | }); |
62 | }); | 62 | }); |
63 | 63 | ||
64 | casper.test.begin('Casper.thenSkip', 2, function(test) { | ||
65 | casper. | ||
66 | thenSkip(1). | ||
67 | then(function () { | ||
68 | test.fail("This test should be skipped."); | ||
69 | }). | ||
70 | then(function () { | ||
71 | test.pass("This test should be executed."); | ||
72 | }); | ||
73 | |||
74 | casper.run(function() { | ||
75 | test.done(); | ||
76 | }); | ||
77 | }); | ||
78 | |||
79 | casper.test.begin('Casper.thenSkipIf', 5, function(test) { | ||
80 | casper. | ||
81 | thenSkipIf(true, 1, "Skip if with function"). | ||
82 | then(function () { | ||
83 | test.fail("This test should be skipped."); | ||
84 | }). | ||
85 | then(function () { | ||
86 | test.pass("This test should be executed."); | ||
87 | }). | ||
88 | thenSkipIf(function () { | ||
89 | return true; | ||
90 | }, 1, "Skip if with function"). | ||
91 | then(function () { | ||
92 | test.fail("This test should be skipped."); | ||
93 | }). | ||
94 | then(function () { | ||
95 | test.pass("This test should be executed."); | ||
96 | }). | ||
97 | thenSkipIf(function () { | ||
98 | return false; | ||
99 | }, 1, "Do not skip if with function"). | ||
100 | then(function () { | ||
101 | test.pass("This test should be executed."); | ||
102 | }); | ||
103 | |||
104 | casper.run(function() { | ||
105 | test.done(); | ||
106 | }); | ||
107 | }); | ||
108 | |||
109 | casper.test.begin('Casper.thenSkipUnless', 5, function(test) { | ||
110 | casper. | ||
111 | thenSkipUnless(false, 1, "Skip unless with function"). | ||
112 | then(function () { | ||
113 | test.fail("This test should be skipped."); | ||
114 | }). | ||
115 | then(function () { | ||
116 | test.pass("This test should be executed."); | ||
117 | }). | ||
118 | thenSkipUnless(function () { | ||
119 | return false; | ||
120 | }, 1, "Skip unless with function"). | ||
121 | then(function () { | ||
122 | test.fail("This test should be skipped."); | ||
123 | }). | ||
124 | then(function () { | ||
125 | test.pass("This test should be executed."); | ||
126 | }). | ||
127 | thenSkipUnless(function () { | ||
128 | return true; | ||
129 | }, 1, "Do not skip unless with function"). | ||
130 | then(function () { | ||
131 | test.pass("This test should be executed."); | ||
132 | }); | ||
133 | |||
134 | casper.run(function() { | ||
135 | test.done(); | ||
136 | }); | ||
137 | }); | ||
138 | ... | ... |
-
Please register or sign in to post a comment