1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-02 09:11:54 +02:00
video.js/test/unit/component.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

module("Component");
test('should create an element', function(){
var comp = new _V_.Component({}, {});
ok(comp.el.nodeName);
});
test('should init child coponents from options', function(){
var comp = new _V_.Component({}, {
components: {
'component': true
}
});
ok(comp.el.childNodes.length === 1);
});
test('should show and hide an element', function(){
var comp = new _V_.Component({}, {});
comp.hide();
ok(comp.el.style.display === 'none');
comp.show();
ok(comp.el.style.display === 'block');
});
test('should add and remove a CSS class', function(){
var comp = new _V_.Component({}, {});
comp.addClass('test-class');
ok(comp.el.className.indexOf('test-class') !== -1);
comp.removeClass('test-class');
ok(comp.el.className.indexOf('test-class') === -1);
});
test('should add and remove event listeners to element', function(){
var comp = new _V_.Component({}, {});
// No need to make this async because we're triggering events inline.
// We're going to trigger the event after removing the listener,
// So if we get extra asserts that's a problem.
expect(1);
var testListener = function(){
ok(true, 'fired event once');
};
comp.on('test-event', testListener);
comp.trigger('test-event');
comp.off('test-event', testListener);
comp.trigger('test-event');
});
test('should trigger a listener once using one()', function(){
var comp = new _V_.Component({}, {});
expect(1);
var testListener = function(){
ok(true, 'fired event once');
};
comp.one('test-event', testListener);
comp.trigger('test-event');
comp.trigger('test-event');
});