Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jul 28, 2021
1 parent beeac3e commit c9578a8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/unit/mixins/evented.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import sinon from 'sinon';
import evented from '../../../src/js/mixins/evented';
import log from '../../../src/js/utils/log';
import DomData from '../../../src/js/utils/dom-data';
import * as Dom from '../../../src/js/utils/dom';
import * as Obj from '../../../src/js/utils/obj';
import * as Events from '../../../src/js/utils/events.js';

// Common errors thrown by evented objects.
const errors = {
Expand Down Expand Up @@ -569,3 +571,31 @@ QUnit.test('off() can remove a listener from an array of events on a different t
target: b.eventBusEl_
});
});

QUnit.test('Removes DomData on dispose', function(assert) {
const el_ = Dom.createEl('div');
const eventBusEl_ = Dom.createEl('span', {className: 'vjs-event-bus'});
const target = evented({el_, eventBusEl_}, {eventBusKey: 'eventBusEl_'});

assert.equal(DomData.get(eventBusEl_).handlers.dispose.length, 1, 'event bus has dispose handler');
assert.notOk(DomData.get(target), 'evented obj has no handlers');
assert.notOk(DomData.get(el_), 'evented el_ has handlers');

target.on('foo', () => {});

assert.equal(DomData.get(eventBusEl_).handlers.foo.length, 1, 'foo handler added to bus');

Events.on(eventBusEl_, 'bar', () => {});
assert.equal(DomData.get(eventBusEl_).handlers.bar.length, 1, 'bar handler added to bus');

Events.on(el_, 'foo', () => {});
assert.equal(DomData.get(el_).handlers.foo.length, 1, 'foo handler added to el_');

Events.on(target, 'foo', () => {});
assert.equal(DomData.get(target).handlers.foo.length, 1, 'foo handler added to evented object');

target.trigger('dispose');
assert.notOk(DomData.get(eventBusEl_), 'eventBusEl_ DomData deleted');
assert.notOk(DomData.get(target), 'evented object DomData deleted');
assert.notOk(DomData.get(el_), 'el_ DomData deleted');
});

0 comments on commit c9578a8

Please sign in to comment.