2015-03-26 06:43:41 +02:00
|
|
|
import CoreObject from '../../src/js/core-object.js';
|
2013-04-09 23:43:35 +03:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
q.module('Core Object');
|
2015-03-11 03:01:11 +02:00
|
|
|
|
2013-04-09 23:43:35 +03:00
|
|
|
test('should verify CoreObject extension', function(){
|
2015-03-26 06:43:41 +02:00
|
|
|
var TestObject = CoreObject.extend({
|
2013-04-09 23:43:35 +03:00
|
|
|
init: function(initOptions){
|
|
|
|
this['a'] = initOptions['a'];
|
|
|
|
},
|
|
|
|
testFn: function(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var instance = new TestObject({ 'a': true });
|
|
|
|
|
|
|
|
ok(instance instanceof TestObject, 'New instance is instance of TestObject');
|
2015-03-26 06:43:41 +02:00
|
|
|
ok(instance instanceof CoreObject, 'New instance is instance of CoreObject');
|
2013-04-09 23:43:35 +03:00
|
|
|
ok(instance['a'], 'Init options are passed to init');
|
|
|
|
ok(instance.testFn(), 'Additional methods are applied to TestObject prototype');
|
|
|
|
|
|
|
|
// Two levels of inheritance
|
|
|
|
var TestChild = TestObject.extend({
|
|
|
|
init: function(initOptions){
|
|
|
|
TestObject.call(this, initOptions);
|
|
|
|
// TestObject.prototype.init.call(this, initOptions);
|
|
|
|
this['b'] = initOptions['b'];
|
|
|
|
},
|
|
|
|
testFn: function(){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var childInstance = new TestChild({ 'a': true, 'b': true });
|
|
|
|
|
|
|
|
ok(childInstance instanceof TestChild, 'New instance is instance of TestChild');
|
|
|
|
ok(childInstance instanceof TestObject, 'New instance is instance of TestObject');
|
2015-03-26 06:43:41 +02:00
|
|
|
ok(childInstance instanceof CoreObject, 'New instance is instance of CoreObject');
|
2013-04-09 23:43:35 +03:00
|
|
|
ok(childInstance['b'], 'Init options are passed to init');
|
|
|
|
ok(childInstance['a'], 'Init options are passed to super init');
|
|
|
|
ok(childInstance.testFn() === false, 'Methods can be overridden by extend');
|
|
|
|
ok(TestObject.prototype.testFn() === true, 'Prototype of parent not overridden');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should verify CoreObject create function', function(){
|
2015-03-26 06:43:41 +02:00
|
|
|
var TestObject = CoreObject.extend({
|
2013-04-09 23:43:35 +03:00
|
|
|
init: function(initOptions){
|
|
|
|
this['a'] = initOptions['a'];
|
|
|
|
},
|
|
|
|
testFn: function(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var instance = TestObject.create({ 'a': true });
|
|
|
|
|
|
|
|
ok(instance instanceof TestObject, 'New instance is instance of TestObject');
|
2015-03-26 06:43:41 +02:00
|
|
|
ok(instance instanceof CoreObject, 'New instance is instance of CoreObject');
|
2013-04-09 23:43:35 +03:00
|
|
|
ok(instance['a'], 'Init options are passed to init');
|
|
|
|
ok(instance.testFn(), 'Additional methods are applied to TestObject prototype');
|
|
|
|
});
|