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:: ...@@ -450,7 +450,7 @@ Asserts that the provided input is of the given type::
450 ``assertInstanceOf()`` 450 ``assertInstanceOf()``
451 ------------------------------------------------------------------------------- 451 -------------------------------------------------------------------------------
452 452
453 **Signature:** ``assertInstanceOf(mixed input, function constructor[, String message])`` 453 **Signature:** ``assertInstanceOf(mixed input, String className[, String message])``
454 454
455 Asserts that the provided input is of the given className:: 455 Asserts that the provided input is of the given className::
456 456
...@@ -461,8 +461,8 @@ Asserts that the provided input is of the given className:: ...@@ -461,8 +461,8 @@ Asserts that the provided input is of the given className::
461 } 461 }
462 casper.test.begin('assertInstanceOf() tests', 2, function suite(test) { 462 casper.test.begin('assertInstanceOf() tests', 2, function suite(test) {
463 var daisy = new Cow(); 463 var daisy = new Cow();
464 test.assertInstanceOf(daisy, Cow, "Okay, daisy is a cow."); 464 test.assertInstanceOf(daisy, "Cow", "Ok, daisy is a cow.");
465 test.assertInstanceOf(daisy, Casper, "Moo is not Boo"); 465 test.assertInstanceOf(["moo", "boo"], "Array", "We can test for arrays too!");
466 test.done(); 466 test.done();
467 }); 467 });
468 468
......
...@@ -843,22 +843,21 @@ Tester.prototype.assertType = function assertType(subject, type, message) { ...@@ -843,22 +843,21 @@ Tester.prototype.assertType = function assertType(subject, type, message) {
843 * Asserts that the provided subject is of the given class name. 843 * Asserts that the provided subject is of the given class name.
844 * 844 *
845 * @param mixed subject The value to test 845 * @param mixed subject The value to test
846 * @param function constructor The object constructor 846 * @param string className The className
847 * @param String message Test description 847 * @param String message Test description
848 * @return Object An assertion result object 848 * @return Object An assertion result object
849 */ 849 */
850 Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, constructor, message) { 850 Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, className, message) {
851 "use strict"; 851 "use strict";
852 if (utils.betterTypeOf(constructor) !== "function") { 852 if (utils.betterTypeOf(constructor) !== "function") {
853 throw new CasperError('Invalid constructor.'); 853 throw new CasperError('Subject is null or undefined.');
854 } 854 }
855 return this.assert(subject instanceof constructor, message, { 855 return this.assert(utils.equals(subject.constructor.name, className), message, {
856 type: "assertInstanceOf", 856 type: "assertInstanceOf",
857 standard: f('Subject is an instance of: "%s"', constructor.name), 857 standard: f('Subject is an instance of: "%s"', constructor.name),
858 values: { 858 values: {
859 subject: subject, 859 subject: subject,
860 constructor: constructor.name, 860 constructor: constructor.name,
861 actual: actual
862 } 861 }
863 }); 862 });
864 }; 863 };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 /*jshint strict:false, maxstatements:99*/ 2 /*jshint strict:false, maxstatements:99*/
3 var fs = require('fs'); 3 var fs = require('fs');
4 4
5 casper.test.begin('Common assertions tests', 46, function(test) { 5 casper.test.begin('Common assertions tests', 50, function(test) {
6 casper.start('tests/site/index.html', function() { 6 casper.start('tests/site/index.html', function() {
7 test.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); 7 test.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text');
8 test.assertTextExist('form', 'Tester.assertTextExist() checks that page body contains text [alias]'); 8 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) { ...@@ -60,9 +60,15 @@ casper.test.begin('Common assertions tests', 46, 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 // we need a constructor and an object 63 // We need two objects to test inheritance case
64 function Cow(){} var daisy = new Cow(); 64 function Cow(){}; function SuperCow(){}; SuperCow.prototype = new Cow;
65 test.assertInstanceOf(daisy, Cow, "Tester.assertInstanceOf() works as expected"); 65 var daisy = new Cow(); var superCowie = new SuperCow();
66 test.assertInstanceOf(12, "Number", "Tester.assertInstanceOf() works as expected");
67 test.assertInstanceOf("Boo", "String", "Tester.assertInstanceOf() works as expected");
68 test.assertInstanceOf(["moo", "bar"], "Array", "Tester.assertInstanceOf() works as expected")
69 test.assertInstanceOf(true, "Boolean", "Test.assertInstanceOf() works as expected");
70 test.assertInstanceOf(daisy, "Cow", "Tester.assertInstanceOf() works as expected");
71 test.assertInstanceOf(superCowie, "SuperCow", "Tester.assertInstanceOf() works as expected");
66 test.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected"); 72 test.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected");
67 test.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]"); 73 test.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]");
68 test.assertVisible('img', 'Tester.assertVisible() works as expected'); 74 test.assertVisible('img', 'Tester.assertVisible() works as expected');
......