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:: ...@@ -445,6 +445,22 @@ Asserts that the provided input is of the given type::
445 445
446 .. note:: Type names are always expressed in lower case. 446 .. note:: Type names are always expressed in lower case.
447 447
448 .. index:: InstanceOf
449
450 ``assertInstanceOf()``
451 -------------------------------------------------------------------------------
452
453 **Signature:** ``assertInstanceOf(mixed input, String className[, String message])``
454
455 Asserts that the provided input is of the given className::
456
457 casper.test.begin('assertInstanceOf() tests', 1, function suite(test) {
458 var daisy = new Cow(){};
459 test.assertInstanceOf(daisy, "Cow", "Okay, daisy is a cow.");
460 test.assertInstanceOf(daisy, "Casper", "Moo is not Boo");
461 test.done();
462 });
463
448 .. index:: URL 464 .. index:: URL
449 465
450 ``assertUrlMatch()`` 466 ``assertUrlMatch()``
......
...@@ -840,6 +840,28 @@ Tester.prototype.assertType = function assertType(subject, type, message) { ...@@ -840,6 +840,28 @@ Tester.prototype.assertType = function assertType(subject, type, message) {
840 }; 840 };
841 841
842 /** 842 /**
843 * Asserts that the provided subject is of the given class name.
844 *
845 * @param mixed subject The value to test
846 * @param String className The javascript class name
847 * @param String message Test description
848 * @return Object An assertion result object
849 */
850 Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, className, message) {
851 "use strict";
852 var actual = subject instanceof className;
853 return this.assert(utils.equals(actual, true), message, {
854 type: "assertType",
855 standard: f('Subject is an instance of: "%s"', className),
856 values: {
857 subject: subject,
858 className: className,
859 actual: actual
860 }
861 });
862 };
863
864 /**
843 * Asserts that a the current page url matches a given pattern. A pattern may be 865 * Asserts that a the current page url matches a given pattern. A pattern may be
844 * either a RegExp object or a String. The method will test if the URL matches 866 * either a RegExp object or a String. The method will test if the URL matches
845 * the pattern or contains the String. 867 * the pattern or contains the String.
......
...@@ -60,6 +60,7 @@ casper.test.begin('Common assertions tests', 45, function(test) { ...@@ -60,6 +60,7 @@ casper.test.begin('Common assertions tests', 45, function(test) {
60 test.assertTitleMatch(/test index/, 'Tester.assertTitleMatch() works as expected'); 60 test.assertTitleMatch(/test index/, 'Tester.assertTitleMatch() works as expected');
61 test.assertTitleMatches(/test index/, 'Tester.assertTitleMatches() works as expected [alias]'); 61 test.assertTitleMatches(/test index/, 'Tester.assertTitleMatches() works as expected [alias]');
62 test.assertType("plop", "string", "Tester.assertType() works as expected"); 62 test.assertType("plop", "string", "Tester.assertType() works as expected");
63 test.assertInstanceOf(casper, "Casper", "Tester.assertInstanceOf() works as expected");
63 test.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected"); 64 test.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected");
64 test.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]"); 65 test.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]");
65 test.assertVisible('img', 'Tester.assertVisible() works as expected'); 66 test.assertVisible('img', 'Tester.assertVisible() works as expected');
......