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
0cb73a8a
...
0cb73a8a0c979c2309f56eb5a130c02cbe35e0ae
authored
2012-12-01 14:42:07 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
enhanced utils.betterTypeOf() to handle `undefined` and `null` values
1 parent
33723622
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
5 deletions
CHANGELOG.md
modules/utils.js
tests/suites/utils.js
CHANGELOG.md
View file @
0cb73a8
...
...
@@ -31,7 +31,8 @@ casper.evaluate(function(a, b) {
-
fixed
[
#274
](
https://github.com/n1k0/casperjs/issues/274
)
- some headers couldn't be set
-
fixed
[
#277
](
https://github.com/n1k0/casperjs/issues/277
)
- multiline support in
`ClientUtils.echo()`
-
fixed
[
#282
](
https://github.com/n1k0/casperjs/issues/282
)
- added support for remote client scripts loading with a new
`remoteScripts`
casper option
-
merged
[
#290
](
https://github.com/n1k0/casperjs/issues/#290
)
- add a simplistic RPM spec file to make it easier to (un)install casperjs
-
fixed
[
#290
](
https://github.com/n1k0/casperjs/issues/#290
)
- add a simplistic RPM spec file to make it easier to (un)install casperjs
-
fixed
[
`utils.betterTypeOf()`
](
http://casperjs.org/api.html#casper.betterTypeOf
)
to properly handle
`undefined`
and
`null`
values
-
fixed
`Casper.die()`
and
`Casper.evaluateOrDie()`
were not printing the error onto the console
-
added
[
`Casper.getFormValues()`
](
http://casperjs.org/api.html#casper.getFormValues
)
to check for the field values of a given form
-
added
[
`Tester.assertTextDoesntExist()`
](
http://casperjs.org/api.html#tester.assertTextDoesntExist
)
...
...
modules/utils.js
View file @
0cb73a8
...
...
@@ -34,16 +34,26 @@
* Provides a better typeof operator equivalent, able to retrieve the array
* type.
*
* CAVEAT: this function does not necessarilly map to classical js "type" names,
* notably a `null` will map to "null" instead of "object".
*
* @param mixed input
* @return String
* @see http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
*/
function
betterTypeOf
(
input
)
{
"use strict"
;
try
{
return
Object
.
prototype
.
toString
.
call
(
input
).
match
(
/^
\[
object
\s(
.*
)\]
$/
)[
1
].
toLowerCase
();
}
catch
(
e
)
{
return
typeof
input
;
switch
(
input
)
{
case
undefined
:
return
'undefined'
;
case
null
:
return
'null'
;
default
:
try
{
return
Object
.
prototype
.
toString
.
call
(
input
).
match
(
/^
\[
object
\s(
.*
)\]
$/
)[
1
].
toLowerCase
();
}
catch
(
e
)
{
return
typeof
input
;
}
}
}
exports
.
betterTypeOf
=
betterTypeOf
;
...
...
tests/suites/utils.js
View file @
0cb73a8
...
...
@@ -4,6 +4,26 @@ var utils = require('utils'),
t
=
casper
.
test
,
x
=
require
(
'casper'
).
selectXPath
;
t
.
comment
(
'betterTypeOf()'
);
(
function
()
{
var
testCases
=
[
{
subject
:
1
,
expected
:
'number'
},
{
subject
:
'1'
,
expected
:
'string'
},
{
subject
:
{},
expected
:
'object'
},
{
subject
:
[],
expected
:
'array'
},
{
subject
:
undefined
,
expected
:
'undefined'
},
{
subject
:
null
,
expected
:
'null'
},
{
subject
:
function
(){},
expected
:
'function'
},
{
subject
:
window
,
expected
:
'domwindow'
},
{
subject
:
new
Date
(),
expected
:
'date'
},
{
subject
:
new
RegExp
(),
expected
:
'regexp'
}
];
testCases
.
forEach
(
function
(
testCase
)
{
t
.
assertEquals
(
utils
.
betterTypeOf
(
testCase
.
subject
),
testCase
.
expected
,
require
(
'utils'
).
format
(
'betterTypeOf() detects expected type "%s"'
,
testCase
.
subject
));
});
})();
t
.
comment
(
'cleanUrl()'
);
(
function
()
{
var
testCases
=
{
...
...
Please
register
or
sign in
to post a comment