Skip to content

Commit

Permalink
Test that cursorDidChange callback not fired after editor is destroyed
Browse files Browse the repository at this point in the history
refs #319
  • Loading branch information
bantic committed Apr 6, 2016
1 parent b337b53 commit 7dc7f8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
18 changes: 1 addition & 17 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,6 @@ class Editor {
this.runCallbacks(CALLBACK_QUEUES.DID_RENDER);
}

addCallback(...args) {
this._callbacks.addCallback(...args);
}

addCallbackOnce(...args) {
this._callbacks.addCallbackOnce(...args);
}

runCallbacks(...args) {
if (this._isDestroyed) {
// warn -- should not run after destroyed
return;
}
this._callbacks.runCallbacks(...args);
}

/**
* @param {Element} element The DOM element to render into.
* Its contents will be replaced by the editor's rendered post.
Expand Down Expand Up @@ -911,7 +895,7 @@ class Editor {

runCallbacks(...args) {
if (this._isDestroyed) {
// warn -- should not run after destroyed
// TODO warn that callback attempted after editor was destroyed
return;
}
this._callbacks.runCallbacks(...args);
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/editor/editor-events-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,22 @@ test('cursorDidChange callback fired after keypress', (assert) => {
done();
});
});

test('cursorDidChange callback not fired if editor is destroyed', (assert) => {
assert.expect(1);
let done = assert.async();

let cursorChanged = 0;
editor.cursorDidChange(() => cursorChanged++);

Helpers.dom.clearSelection();
Helpers.dom.triggerEvent(document, 'mouseup');
editor.destroy();
editor = null;

setTimeout(() => {
assert.equal(cursorChanged, 0, 'callback not fired');

done();
});
});

0 comments on commit 7dc7f8d

Please sign in to comment.