Skip to content

Commit

Permalink
Add tests for OOP in React UI
Browse files Browse the repository at this point in the history
Fixes #152
  • Loading branch information
ipeychev committed Mar 25, 2015
1 parent de1e11f commit c82464b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
14 changes: 1 addition & 13 deletions src/ui/react/src/oop/oop.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
(function () {
'use strict';

// unceremoniously lifted from YUI
var create = Object.create ? function (obj) {
return Object.create(obj);
} : (function () {
function F() {}

return function (obj) {
F.prototype = obj;
return new F();
};
}());

var OOP = {
/**
* Sets the prototype, constructor and superclass properties to support an inheritance strategy
Expand All @@ -29,7 +17,7 @@
throw 'extend failed, verify dependencies';
}

var supplierProto = supplier.prototype, receiverProto = create(supplierProto);
var supplierProto = supplier.prototype, receiverProto = Object.create(supplierProto);
receiver.prototype = receiverProto;

receiverProto.constructor = receiver;
Expand Down
60 changes: 60 additions & 0 deletions src/ui/react/test/oop.js
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);
});
});
});

0 comments on commit c82464b

Please sign in to comment.