1
0
Fork 0

Began adding parent tests (parent method call currently fails)

closure/master
Mike Gerwitz 2010-11-10 22:19:50 -05:00
parent 26b70bcd93
commit 6ea6fd0bb7
1 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,89 @@
/**
* Tests class parent invocation
*
* Copyright (C) 2010 Mike Gerwitz
*
* This file is part of ease.js.
*
* ease.js is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Mike Gerwitz
* @package test
*/
require( './common' );
var assert = require( 'assert' ),
Class = require( 'class' );
var Foo = Class.extend(
{
hitMethod: false,
hitMethod2: false,
myMethod: function()
{
this.hitMethod = true;
return this;
},
myMethod2: function()
{
this.hitMethod2 = true;
return this;
},
});
var SubFoo = Foo.extend(
{
myMethod: function()
{
return this;
},
myMethod2: function()
{
return this._super();
},
});
var foo = new Foo(),
sub_foo = new SubFoo();
// make sure we're working properly before we run the important assertions
foo.myMethod().myMethod2();
assert.equal(
foo.hitMethod,
true,
"Sanity check"
);
assert.equal(
foo.hitMethod2,
true,
"Sanity check"
);
// myMethod overrides without calling parent
assert.equal(
sub_foo.hitMethod,
false,
"Subtype should be able to override parent properties"
);
assert.equal(
sub_foo.hitMethod2,
true,
"Subtype should be able to call parent method"
);