Skip to content

Commit

Permalink
fix: clear readyQueue with dispose (#6967)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Dec 11, 2020
1 parent 3e30f83 commit 11d37e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/js/component.js
Expand Up @@ -138,6 +138,10 @@ class Component {
return;
}

if (this.readyQueue_) {
this.readyQueue_.length = 0;
}

/**
* Triggered when a `Component` is disposed.
*
Expand Down
26 changes: 26 additions & 0 deletions test/unit/component.test.js
Expand Up @@ -1390,3 +1390,29 @@ QUnit.test('getDescendant should work as expected', function(assert) {

comp.dispose();
});

QUnit.test('ready queue should not run after dispose', function(assert) {
let option = false;
let callback = false;

const comp = new Component(this.player, {name: 'component'}, () => {
option = true;
});

comp.ready(() => {
callback = true;
});

comp.dispose();
comp.triggerReady();
// TODO: improve this error. It is a variant of:
// "Cannot read property 'parentNode' of null"
//
// but on some browsers such as IE 11 and safari 9 other errors are thrown,
// I think any error at all works for our purposes here.
assert.throws(() => this.clock.tick(1), /.*/, 'throws trigger error');

assert.notOk(option, 'ready option not run');
assert.notOk(callback, 'ready callback not run');

});

0 comments on commit 11d37e2

Please sign in to comment.