From fdf389ba2e979a1e65608b0726211ff6a684b593 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 10 Nov 2010 21:39:09 -0500 Subject: [PATCH] Added inheritance instanceof assertions --- test/test-class-extend.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/test-class-extend.js b/test/test-class-extend.js index be862ef..46e1824 100644 --- a/test/test-class-extend.js +++ b/test/test-class-extend.js @@ -66,3 +66,34 @@ for ( var prop in sub_props ) "Subtype contains its own properties: " + prop ); } + +assert.ok( + ( new SubFoo() instanceof Foo ), + "Subtypes must be considered to be instances of their supertypes" +); + + +// Foo +// | +// SubFoo +// / \ +// SubSubFoo SubSubFoo2 +// +var SubSubFoo = SubFoo.extend(), + SubSubFoo2 = SubFoo.extend(); + +assert.ok( + ( new SubSubFoo() instanceof Foo ), + "Sub-subtypes should be instances of their super-supertype" +); + +assert.ok( + !( new SubFoo() instanceof SubSubFoo ), + "Supertypes should not be considered instances of their subtypes" +); + +assert.ok( + !( new SubSubFoo2() instanceof SubSubFoo ), + "Subtypes should not be considered instances of their siblings" +); +