Correct method, tests and documentation
Showing
3 changed files
with
22 additions
and
15 deletions
... | @@ -450,14 +450,19 @@ Asserts that the provided input is of the given type:: | ... | @@ -450,14 +450,19 @@ Asserts that the provided input is of the given type:: |
450 | ``assertInstanceOf()`` | 450 | ``assertInstanceOf()`` |
451 | ------------------------------------------------------------------------------- | 451 | ------------------------------------------------------------------------------- |
452 | 452 | ||
453 | **Signature:** ``assertInstanceOf(mixed input, String className[, String message])`` | 453 | **Signature:** ``assertInstanceOf(mixed input, function constructor[, 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 | ||
457 | function Cow() { | ||
458 | this.moo = function moo() { | ||
459 | return 'moo!'; | ||
460 | }; | ||
461 | } | ||
457 | casper.test.begin('assertInstanceOf() tests', 1, function suite(test) { | 462 | casper.test.begin('assertInstanceOf() tests', 1, function suite(test) { |
458 | var daisy = new Cow(){}; | 463 | var daisy = new Cow(); |
459 | test.assertInstanceOf(daisy, "Cow", "Okay, daisy is a cow."); | 464 | test.assertInstanceOf(daisy, Cow, "Okay, daisy is a cow."); |
460 | test.assertInstanceOf(daisy, "Casper", "Moo is not Boo"); | 465 | test.assertInstanceOf(daisy, Casper, "Moo is not Boo"); |
461 | test.done(); | 466 | test.done(); |
462 | }); | 467 | }); |
463 | 468 | ... | ... |
... | @@ -842,20 +842,20 @@ Tester.prototype.assertType = function assertType(subject, type, message) { | ... | @@ -842,20 +842,20 @@ Tester.prototype.assertType = function assertType(subject, type, message) { |
842 | /** | 842 | /** |
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 String className The javascript class name | 846 | * @param function constructor The object constructor |
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, className, message) { | 850 | Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, constructor, message) { |
851 | "use strict"; | 851 | "use strict"; |
852 | var actual = subject instanceof className; | 852 | var actual = subject instanceof constructor; |
853 | return this.assert(utils.equals(actual, true), message, { | 853 | return this.assert(utils.equals(actual, true), message, { |
854 | type: "assertInstanceOf", | 854 | type: "assertInstanceOf", |
855 | standard: f('Subject is an instance of: "%s"', className), | 855 | standard: f('Subject is an instance of: "%s"', constructor), |
856 | values: { | 856 | values: { |
857 | subject: subject, | 857 | subject: subject, |
858 | className: className, | 858 | constructor: constructor, |
859 | actual: actual | 859 | actual: actual |
860 | } | 860 | } |
861 | }); | 861 | }); | ... | ... |
... | @@ -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', 45, function(test) { | 5 | casper.test.begin('Common assertions tests', 46, 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,7 +60,9 @@ casper.test.begin('Common assertions tests', 45, function(test) { | ... | @@ -60,7 +60,9 @@ 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 | // we need a constructor and an object |
64 | function Cow(){}; var daisy = new Cow(); | ||
65 | test.assertInstanceOf(daisy, Cow, "Tester.assertInstanceOf() works as expected"); | ||
64 | test.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected"); | 66 | test.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected"); |
65 | test.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]"); | 67 | test.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]"); |
66 | test.assertVisible('img', 'Tester.assertVisible() works as expected'); | 68 | test.assertVisible('img', 'Tester.assertVisible() works as expected'); | ... | ... |
-
Please register or sign in to post a comment