-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #152
- Loading branch information
Showing
2 changed files
with
61 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
var assert = chai.assert; | ||
|
||
describe('lang', function() { | ||
this.timeout(35000); | ||
|
||
describe('OOP', function() { | ||
it('should extend a class from another class', function() { | ||
var Parent = function() {}; | ||
|
||
Parent.prototype.method1 = function() { | ||
return 1; | ||
}; | ||
|
||
var Child = function(config) { | ||
Child.superclass.constructor.call(this, config); | ||
}; | ||
|
||
Child = global.OOP.extend(Child, Parent); | ||
|
||
var child = new Child(); | ||
|
||
assert.strictEqual(1, child.method1()); | ||
}); | ||
|
||
it('should extend a class from another class with proto overwrites and statics', function() { | ||
var Parent = function() {}; | ||
|
||
Parent.prototype.method1 = function(a) { | ||
return ++a; | ||
}; | ||
|
||
var Child = function(config) { | ||
Child.superclass.constructor.call(this, config); | ||
}; | ||
|
||
Child = global.OOP.extend(Child, Parent, { | ||
method1: function() { | ||
return 7; | ||
} | ||
}, { | ||
STATIC1: 'static1' | ||
}); | ||
|
||
var child = new Child(); | ||
|
||
assert.strictEqual(7, child.method1()); | ||
assert.strictEqual('static1', Child.STATIC1); | ||
}); | ||
}); | ||
|
||
it('should throw exception when no parent or child', function() { | ||
assert.throws(function () { | ||
var Parent = function() {}; | ||
|
||
global.OOP.extend(null, Parent); | ||
}); | ||
}); | ||
}); |