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
e6d651c6
...
e6d651c648f233c8a2573d9a10e4340494cb0957
authored
2011-12-09 21:29:00 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
improved Tester.assertEquals() to allow comparison of arrays
1 parent
b8be54b5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
3 deletions
casper.js
casper.js
View file @
e6d651c
...
...
@@ -1379,6 +1379,21 @@
var
PASS
=
this
.
options
.
PASS
||
"PASS"
;
var
FAIL
=
this
.
options
.
FAIL
||
"FAIL"
;
function
compareArrays
(
a
,
b
)
{
if
(
a
.
length
!==
b
.
length
)
{
return
false
;
}
a
.
forEach
(
function
(
item
,
i
)
{
if
(
isType
(
item
,
"array"
)
&&
!
compareArrays
(
item
,
b
[
i
]))
{
return
false
;
}
if
(
item
!==
b
[
i
])
{
return
false
;
}
});
return
true
;
}
// properties
this
.
testResults
=
{
passed
:
0
,
...
...
@@ -1410,12 +1425,23 @@
/**
* Asserts that two values are strictly equals.
*
* @param
Boolean
testValue The value to test
* @param
Boolean
expected The expected value
* @param
Mixed
testValue The value to test
* @param
Mixed
expected The expected value
* @param String message Test description
*/
this
.
assertEquals
=
function
(
testValue
,
expected
,
message
)
{
if
(
expected
===
testValue
)
{
var
result
;
if
(
typeof
testValue
!==
typeof
expected
)
{
result
=
false
;
}
else
if
(
isType
(
testValue
,
"array"
))
{
result
=
compareArrays
(
testValue
,
expected
);
}
else
if
(
isType
(
testValue
,
"object"
)
&&
isType
(
expected
,
"object"
))
{
// comparing objects equality in Javascript is UTOPIA
throw
"Tester.assertEquals() cannot compare objects, sorry"
;
}
else
{
result
=
expected
===
testValue
;
}
if
(
result
===
true
)
{
casper
.
echo
(
this
.
colorize
(
PASS
,
'INFO'
)
+
' '
+
this
.
formatMessage
(
message
));
this
.
testResults
.
passed
++
;
exporter
.
addSuccess
(
"unknown"
,
message
);
...
...
Please
register
or
sign in
to post a comment