mirror of
https://github.com/videojs/video.js.git
synced 2025-07-15 01:34:23 +02:00
feat: Add 'beforepluginsetup' event and named plugin setup events (e.g. 'pluginsetup:foo') (#4255)
This adds a beforepluginsetup event as well as beforepluginsetup:$name and pluginsetup:$name events. The drive behind this is improving the ability for people to make cross-plugin dependencies in a more robust manner.
This commit is contained in:
committed by
Gary Katsevman
parent
da1d8613d7
commit
0a19cf0d6a
@ -47,23 +47,35 @@ QUnit.test('setup', function(assert) {
|
||||
assert.ok(this.player.hasPlugin('basic'), 'player has the plugin available');
|
||||
});
|
||||
|
||||
QUnit.test('"pluginsetup" event', function(assert) {
|
||||
QUnit.test('all "pluginsetup" events', function(assert) {
|
||||
const setupSpy = sinon.spy();
|
||||
const events = [
|
||||
'beforepluginsetup',
|
||||
'beforepluginsetup:basic',
|
||||
'pluginsetup',
|
||||
'pluginsetup:basic'
|
||||
];
|
||||
|
||||
this.player.on('pluginsetup', setupSpy);
|
||||
this.player.on(events, setupSpy);
|
||||
|
||||
const instance = this.player.basic();
|
||||
const event = setupSpy.firstCall.args[0];
|
||||
const hash = setupSpy.firstCall.args[1];
|
||||
|
||||
assert.strictEqual(setupSpy.callCount, 1, 'the "pluginsetup" event was triggered');
|
||||
assert.strictEqual(event.type, 'pluginsetup', 'the event has the correct type');
|
||||
events.forEach((type, i) => {
|
||||
const event = setupSpy.getCall(i).args[0];
|
||||
const hash = setupSpy.getCall(i).args[1];
|
||||
|
||||
assert.deepEqual(hash, {
|
||||
name: 'basic',
|
||||
instance,
|
||||
plugin: this.basic
|
||||
}, 'the event hash object is correct');
|
||||
assert.strictEqual(event.type, type, `the "${type}" event was triggered`);
|
||||
assert.strictEqual(event.target, this.player.el_, 'the event has the correct target');
|
||||
|
||||
assert.deepEqual(hash, {
|
||||
name: 'basic',
|
||||
|
||||
// The "before" events have a `null` instance and the others have the
|
||||
// return value of the plugin factory.
|
||||
instance: i < 2 ? null : instance,
|
||||
plugin: this.basic
|
||||
}, 'the event hash object is correct');
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('properties are copied', function(assert) {
|
||||
|
Reference in New Issue
Block a user