1
0
Fork 0

Added test for good measure to ensure class instances do not share protected member values

closure/master
Mike Gerwitz 2011-03-07 00:19:56 -05:00
parent e05a65d5fa
commit 4e2f174667
1 changed files with 33 additions and 1 deletions

View File

@ -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)"
);
} )();