Commit c7d5a1cf c7d5a1cf2fe536f6dd1e07d3af05d0d9164e48e2 by mickaelandrieu Committed by Mickaël Andrieu

introduce new assertInstanceOf() method

1 parent 55b7b251
......@@ -445,6 +445,22 @@ Asserts that the provided input is of the given type::
.. note:: Type names are always expressed in lower case.
.. index:: InstanceOf
``assertInstanceOf()``
-------------------------------------------------------------------------------
**Signature:** ``assertInstanceOf(mixed input, String className[, String message])``
Asserts that the provided input is of the given className::
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");
test.done();
});
.. index:: URL
``assertUrlMatch()``
......
......@@ -840,6 +840,28 @@ 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
*/
Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, className, message) {
"use strict";
var actual = subject instanceof className;
return this.assert(utils.equals(actual, true), message, {
type: "assertType",
standard: f('Subject is an instance of: "%s"', className),
values: {
subject: subject,
className: className,
actual: actual
}
});
};
/**
* Asserts that a the current page url matches a given pattern. A pattern may be
* either a RegExp object or a String. The method will test if the URL matches
* the pattern or contains the String.
......
......@@ -60,6 +60,7 @@ 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");
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');
......