Commit 15411690 15411690edb0cf182eb847fb44109c77fdfd56d4 by mickaelandrieu Committed by Mickaël Andrieu

Correct method, tests and documentation

1 parent 36474308
......@@ -450,14 +450,19 @@ Asserts that the provided input is of the given type::
``assertInstanceOf()``
-------------------------------------------------------------------------------
**Signature:** ``assertInstanceOf(mixed input, String className[, String message])``
**Signature:** ``assertInstanceOf(mixed input, function constructor[, String message])``
Asserts that the provided input is of the given className::
function Cow() {
this.moo = function moo() {
return 'moo!';
};
}
casper.test.begin('assertInstanceOf() tests', 1, function suite(test) {
var daisy = new Cow(){};
test.assertInstanceOf(daisy, "Cow", "Okay, daisy is a cow.");
test.assertInstanceOf(daisy, "Casper", "Moo is not Boo");
var daisy = new Cow();
test.assertInstanceOf(daisy, Cow, "Okay, daisy is a cow.");
test.assertInstanceOf(daisy, Casper, "Moo is not Boo");
test.done();
});
......
......@@ -842,20 +842,20 @@ 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 String className The javascript class name
* @param String message Test description
* @return Object An assertion result object
* @param mixed subject The value to test
* @param function constructor The object constructor
* @param String message Test description
* @return Object An assertion result object
*/
Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, className, message) {
Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, constructor, message) {
"use strict";
var actual = subject instanceof className;
var actual = subject instanceof constructor;
return this.assert(utils.equals(actual, true), message, {
type: "assertInstanceOf",
standard: f('Subject is an instance of: "%s"', className),
standard: f('Subject is an instance of: "%s"', constructor),
values: {
subject: subject,
className: className,
constructor: constructor,
actual: actual
}
});
......
......@@ -2,7 +2,7 @@
/*jshint strict:false, maxstatements:99*/
var fs = require('fs');
casper.test.begin('Common assertions tests', 45, function(test) {
casper.test.begin('Common assertions tests', 46, 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,7 +60,9 @@ casper.test.begin('Common assertions tests', 45, 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");
test.assertInstanceOf(casper, "Casper", "Tester.assertInstanceOf() 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");
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');
......