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
33271089
...
33271089eeb0570f285265d2a78fb228b02db15b
authored
2013-09-09 00:58:28 +0200
by
Mickaël Andrieu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Update method, add tests and correct documentation
Will now works as I expected before :)
1 parent
e76147f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
12 deletions
docs/modules/tester.rst
modules/tester.js
tests/suites/tester/assert.js
docs/modules/tester.rst
View file @
3327108
...
...
@@ -450,7 +450,7 @@ Asserts that the provided input is of the given type::
``assertInstanceOf()``
-------------------------------------------------------------------------------
**Signature:** ``assertInstanceOf(mixed input,
function constructor
[, String message])``
**Signature:** ``assertInstanceOf(mixed input,
String className
[, String message])``
Asserts that the provided input is of the given className::
...
...
@@ -461,8 +461,8 @@ Asserts that the provided input is of the given className::
}
casper.test.begin('assertInstanceOf() tests', 2, function suite(test) {
var daisy = new Cow();
test.assertInstanceOf(daisy,
Cow, "Okay
, daisy is a cow.");
test.assertInstanceOf(
daisy, Casper, "Moo is not Boo
");
test.assertInstanceOf(daisy,
"Cow", "Ok
, daisy is a cow.");
test.assertInstanceOf(
["moo", "boo"], "Array", "We can test for arrays too!
");
test.done();
});
...
...
modules/tester.js
View file @
3327108
...
...
@@ -843,22 +843,21 @@ Tester.prototype.assertType = function assertType(subject, type, message) {
* Asserts that the provided subject is of the given class name.
*
* @param mixed subject The value to test
* @param
function constructor The object constructor
* @param
string className The className
* @param String message Test description
* @return Object An assertion result object
*/
Tester
.
prototype
.
assertInstanceOf
=
function
assertInstanceOf
(
subject
,
c
onstructor
,
message
)
{
Tester
.
prototype
.
assertInstanceOf
=
function
assertInstanceOf
(
subject
,
c
lassName
,
message
)
{
"use strict"
;
if
(
utils
.
betterTypeOf
(
constructor
)
!==
"function"
)
{
throw
new
CasperError
(
'
Invalid constructor
.'
);
throw
new
CasperError
(
'
Subject is null or undefined
.'
);
}
return
this
.
assert
(
subject
instanceof
constructor
,
message
,
{
return
this
.
assert
(
utils
.
equals
(
subject
.
constructor
.
name
,
className
)
,
message
,
{
type
:
"assertInstanceOf"
,
standard
:
f
(
'Subject is an instance of: "%s"'
,
constructor
.
name
),
values
:
{
subject
:
subject
,
constructor
:
constructor
.
name
,
actual
:
actual
}
});
};
...
...
tests/suites/tester/assert.js
View file @
3327108
...
...
@@ -2,7 +2,7 @@
/*jshint strict:false, maxstatements:99*/
var
fs
=
require
(
'fs'
);
casper
.
test
.
begin
(
'Common assertions tests'
,
46
,
function
(
test
)
{
casper
.
test
.
begin
(
'Common assertions tests'
,
50
,
function
(
test
)
{
casper
.
start
(
'tests/site/index.html'
,
function
()
{
test
.
assertTextExists
(
'form'
,
'Tester.assertTextExists() checks that page body contains text'
);
test
.
assertTextExist
(
'form'
,
'Tester.assertTextExist() checks that page body contains text [alias]'
);
...
...
@@ -60,9 +60,15 @@ casper.test.begin('Common assertions tests', 46, function(test) {
test
.
assertTitleMatch
(
/test index/
,
'Tester.assertTitleMatch() works as expected'
);
test
.
assertTitleMatches
(
/test index/
,
'Tester.assertTitleMatches() works as expected [alias]'
);
test
.
assertType
(
"plop"
,
"string"
,
"Tester.assertType() works as expected"
);
// we need a constructor and an object
function
Cow
(){}
var
daisy
=
new
Cow
();
test
.
assertInstanceOf
(
daisy
,
Cow
,
"Tester.assertInstanceOf() works as expected"
);
// We need two objects to test inheritance case
function
Cow
(){};
function
SuperCow
(){};
SuperCow
.
prototype
=
new
Cow
;
var
daisy
=
new
Cow
();
var
superCowie
=
new
SuperCow
();
test
.
assertInstanceOf
(
12
,
"Number"
,
"Tester.assertInstanceOf() works as expected"
);
test
.
assertInstanceOf
(
"Boo"
,
"String"
,
"Tester.assertInstanceOf() works as expected"
);
test
.
assertInstanceOf
([
"moo"
,
"bar"
],
"Array"
,
"Tester.assertInstanceOf() works as expected"
)
test
.
assertInstanceOf
(
true
,
"Boolean"
,
"Test.assertInstanceOf() works as expected"
);
test
.
assertInstanceOf
(
daisy
,
"Cow"
,
"Tester.assertInstanceOf() works as expected"
);
test
.
assertInstanceOf
(
superCowie
,
"SuperCow"
,
"Tester.assertInstanceOf() works as expected"
);
test
.
assertUrlMatch
(
/index
\.
html$/
,
"Tester.assertUrlMatch() works as expected"
);
test
.
assertUrlMatches
(
/index
\.
html$/
,
"Tester.assertUrlMatches() works as expected [alias]"
);
test
.
assertVisible
(
'img'
,
'Tester.assertVisible() works as expected'
);
...
...
Please
register
or
sign in
to post a comment