From 4e2f1746674b5ae0c02ddfc82169f2fb4e4fe5e4 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 7 Mar 2011 00:19:56 -0500 Subject: [PATCH] Added test for good measure to ensure class instances do not share protected member values --- test/test-class-visibility.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/test-class-visibility.js b/test/test-class-visibility.js index c535a75..be5df66 100644 --- a/test/test-class-visibility.js +++ b/test/test-class-visibility.js @@ -66,7 +66,8 @@ var common = require( './common' ), foo = Foo(), // subtype - sub_foo = Foo.extend( {} )() + SubFoo = Foo.extend( {} ), + sub_foo = SubFoo() ; @@ -276,3 +277,34 @@ var common = require( './common' ), ); } )(); + +/** + * For good measure, let's make sure we didn't screw anything up. To ensure that + * the same object isn't being passed around to subtypes, ensure that multiple + * class instances do not share prototypes. + */ +( function testProtectedMembersAreNotSharedBetweenClassInstances() +{ + var val = 'foobar'; + + foo.setValue( 'prot', val ); + + // ensure that class instances do not share values (ensuring the same object + // isn't somehow being passed around) + assert.notEqual( + sub_foo.getProp( 'prot' ), + val, + "Class instances do not share protected values (subtype)" + ); + + // do the same for multiple instances of the same type + var sub_foo2 = SubFoo(); + sub_foo2.setValue( 'prot', val ); + + assert.notEqual( + sub_foo.getProp( 'prot' ), + val, + "Class instances do not share protected values (same type)" + ); +} )(); +