Commit 33271089 33271089eeb0570f285265d2a78fb228b02db15b by Mickaël Andrieu

Update method, add tests and correct documentation

Will now works as I expected before :)
1 parent e76147f1
......@@ -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();
});
......
......@@ -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, constructor, message) {
Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, className, 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
}
});
};
......
......@@ -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');
......