From b357293890a2860b4ef77942e63826b28bfd5751 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 29 Dec 2010 21:45:33 -0500 Subject: [PATCH] Classes now tested using isInstanceOf() --- test/test-class-extend.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/test/test-class-extend.js b/test/test-class-extend.js index 00839d3..3061147 100644 --- a/test/test-class-extend.js +++ b/test/test-class-extend.js @@ -68,12 +68,21 @@ for ( var prop in sub_props ) ); } + +var sub_instance = new SubFoo(); + assert.ok( - ( new SubFoo() instanceof Foo ), + ( sub_instance instanceof Foo ), "Subtypes are considered to be instances of their supertypes " + "(via instanceof operator)" ); +assert.ok( + sub_instance.isInstanceOf( SubFoo ), + "Subtypes are considered to be instances of their supertypes (via " + + "isInstanceOf method)" +); + // Foo // | @@ -82,20 +91,29 @@ assert.ok( // SubSubFoo SubSubFoo2 // var SubSubFoo = SubFoo.extend(), - SubSubFoo2 = SubFoo.extend(); + SubSubFoo2 = SubFoo.extend(), + + sub_sub_instance = new SubSubFoo(), + sub_sub2_instance = new SubSubFoo2(); assert.ok( - ( new SubSubFoo() instanceof Foo ), + ( ( sub_sub_instance instanceof Foo ) + && sub_sub_instance.isInstanceOf( Foo ) + ), "Sub-subtypes should be instances of their super-supertype" ); assert.ok( - !( new SubFoo() instanceof SubSubFoo ), + ( !( sub_instance instanceof SubSubFoo ) + && !( sub_instance.isInstanceOf( SubSubFoo ) ) + ), "Supertypes should not be considered instances of their subtypes" ); assert.ok( - !( new SubSubFoo2() instanceof SubSubFoo ), + ( !( sub_sub2_instance instanceof SubSubFoo ) + && !( sub_sub2_instance.isInstanceOf( SubSubFoo ) ) + ), "Subtypes should not be considered instances of their siblings" );