Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
ada90f6a
...
ada90f6a9c99a7f8bf7034ab8fa95a95a414d61d
authored
2011-10-16 00:55:35 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixed Casper#each didn't pass the correct index argument, added tests
1 parent
214ed0c3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
casper.js
tests/run.js
casper.js
View file @
ada90f6
...
...
@@ -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
);
};
/**
...
...
tests/run.js
View file @
ada90f6
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
();
...
...
Please
register
or
sign in
to post a comment