test-class-parent no longer relies on member visibility to succeed
- This is important for pending changesclosure/master
parent
02d0c07f98
commit
40228361a1
|
@ -26,29 +26,31 @@ var common = require( './common' ),
|
||||||
assert = require( 'assert' ),
|
assert = require( 'assert' ),
|
||||||
Class = common.require( 'class' );
|
Class = common.require( 'class' );
|
||||||
|
|
||||||
var Foo = Class.extend(
|
// we store these outside of the class to ensure that visibility bugs do not
|
||||||
{
|
// get in the way of our assertions
|
||||||
hitMethod: false,
|
hitMethod = false,
|
||||||
hitMethod2: false,
|
hitMethod2 = false,
|
||||||
method2Arg: null,
|
method2Arg = null,
|
||||||
|
|
||||||
|
Foo = Class.extend(
|
||||||
|
{
|
||||||
myMethod: function()
|
myMethod: function()
|
||||||
{
|
{
|
||||||
this.hitMethod = true;
|
hitMethod = true;
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
myMethod2: function( arg )
|
myMethod2: function( arg )
|
||||||
{
|
{
|
||||||
this.hitMethod2 = true;
|
hitMethod2 = true;
|
||||||
this.method2Arg = arg;
|
method2Arg = arg;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
|
||||||
var SubFoo = Foo.extend(
|
SubFoo = Foo.extend(
|
||||||
{
|
{
|
||||||
myMethod: function()
|
myMethod: function()
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
|
@ -63,43 +65,46 @@ var SubFoo = Foo.extend(
|
||||||
{
|
{
|
||||||
return this.parent.myMethod2.apply( this, arguments );
|
return this.parent.myMethod2.apply( this, arguments );
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
|
||||||
var foo = new Foo(),
|
foo = new Foo(),
|
||||||
sub_foo = new SubFoo();
|
sub_foo = new SubFoo()
|
||||||
|
;
|
||||||
|
|
||||||
// make sure we're working properly before we run the important assertions
|
// make sure we're working properly before we run the important assertions
|
||||||
foo.myMethod().myMethod2();
|
foo.myMethod().myMethod2();
|
||||||
assert.equal(
|
assert.equal(
|
||||||
foo.hitMethod,
|
hitMethod,
|
||||||
true,
|
true,
|
||||||
"Sanity check"
|
"Sanity check"
|
||||||
);
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
foo.hitMethod2,
|
hitMethod2,
|
||||||
true,
|
true,
|
||||||
"Sanity check"
|
"Sanity check"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
hitMethod = hitMethod2 = false;
|
||||||
|
|
||||||
var arg = 'foobar';
|
var arg = 'foobar';
|
||||||
sub_foo.myMethod().myMethod2( arg );
|
sub_foo.myMethod().myMethod2( arg );
|
||||||
|
|
||||||
// myMethod overrides without calling parent
|
// myMethod overrides without calling parent
|
||||||
assert.equal(
|
assert.equal(
|
||||||
sub_foo.hitMethod,
|
hitMethod,
|
||||||
false,
|
false,
|
||||||
"Subtype should be able to override parent properties"
|
"Subtype should be able to override parent properties"
|
||||||
);
|
);
|
||||||
|
|
||||||
// myMethod2 overrides parent then calls super method
|
// myMethod2 overrides parent then calls super method
|
||||||
assert.equal(
|
assert.equal(
|
||||||
sub_foo.hitMethod2,
|
hitMethod2,
|
||||||
true,
|
true,
|
||||||
"Subtype should be able to call parent method"
|
"Subtype should be able to call parent method"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
sub_foo.method2Arg,
|
method2Arg,
|
||||||
arg,
|
arg,
|
||||||
"Arguments should be passed to super method via _super argument list"
|
"Arguments should be passed to super method via _super argument list"
|
||||||
);
|
);
|
||||||
|
@ -112,7 +117,7 @@ assert.deepEqual(
|
||||||
|
|
||||||
sub_foo.callParentAlt( arg = 'moo' );
|
sub_foo.callParentAlt( arg = 'moo' );
|
||||||
assert.equal(
|
assert.equal(
|
||||||
sub_foo.method2Arg,
|
method2Arg,
|
||||||
arg,
|
arg,
|
||||||
"The parent property may also be used to invoke parent methods"
|
"The parent property may also be used to invoke parent methods"
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue