1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-14 11:23:30 +02:00
video.js/test/unit/core-object.js

59 lines
2.1 KiB
JavaScript
Raw Normal View History

module('Core Object');
test('should verify CoreObject extension', function(){
var TestObject = vjs.CoreObject.extend({
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');
ok(instance instanceof vjs.CoreObject, 'New instance is instance of CoreObject');
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');
ok(childInstance instanceof vjs.CoreObject, 'New instance is instance of CoreObject');
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(){
var TestObject = vjs.CoreObject.extend({
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');
ok(instance instanceof vjs.CoreObject, 'New instance is instance of CoreObject');
ok(instance['a'], 'Init options are passed to init');
ok(instance.testFn(), 'Additional methods are applied to TestObject prototype');
});