Commit ada90f6a ada90f6a9c99a7f8bf7034ab8fa95a95a414d61d by Nicolas Perriault

fixed Casper#each didn't pass the correct index argument, added tests

1 parent 214ed0c3
......@@ -231,13 +231,25 @@
return this.exit(Number(status) > 0 ? Number(status) : 1);
},
/**
* Iterates over the values of a provided array and execute a callback
* for each item.
*
* @param Array array
* @param Function fn Callback: function(self, item, index)
* @return Casper
*/
each: function(array, fn) {
var i = 0;
(function(self, i) {
array.forEach(function(item) {
if (array.constructor !== Array) {
self.log("each() only works with arrays", "error");
return this;
}
(function(self) {
array.forEach(function(item, i) {
fn(self, item, i);
});
})(this, i);
})(this);
return this;
},
......@@ -1033,9 +1045,7 @@
* @param String message Test description
*/
this.assertTitle = function(expected, message) {
return this.assertEvalEquals(function() {
return document.title;
}, expected, message);
return this.assertEquals(casper.getTitle(), expected, message);
};
/**
......
phantom.injectJs('casper.js');
var casper = new phantom.Casper({
faultTolerant: false
faultTolerant: false,
verbose: true
});
var save = null;
......@@ -99,6 +100,11 @@ casper.then(function(self) {
self.test.assertUrlMatch(/topic=bar/, 'fill() select field was submitted');
});
// Casper#each()
casper.each([1, 2, 3], function(self, item, i) {
self.test.assertEquals(i, item - 1, 'each() passes a contextualized index');
});
// Casper.XUnitExporter
casper.test.comment('phantom.Casper.XUnitExporter');
xunit = new phantom.Casper.XUnitExporter();
......