A platform for community discussion. Free, open, simple.
DEV: prevents toolbar callbacks to leak between tests (#9403)
Joffrey JAFFEUX058506bb7768
diff --git a/app/assets/javascripts/discourse/components/d-editor.js b/app/assets/javascripts/discourse/components/d-editor.jsindex b83b667bca7..199266c2a89 100644--- a/app/assets/javascripts/discourse/components/d-editor.js+++ b/app/assets/javascripts/discourse/components/d-editor.js@@ -52,7 +52,7 @@ const OP = {const FOUR_SPACES_INDENT = "4-spaces-indent";-const _createCallbacks = [];+let _createCallbacks = [];const isInside = (text, regex) => {const matches = text.match(regex);@@ -212,6 +212,9 @@ class Toolbar {export function addToolbarCallback(func) {_createCallbacks.push(func);}+export function clearToolbarCallbacks() {+ _createCallbacks = [];+}export function onToolbarCreate(func) {deprecated("`onToolbarCreate` is deprecated, use the plugin api instead.");diff --git a/test/javascripts/components/d-editor-test.js b/test/javascripts/components/d-editor-test.jsindex 131de74e68f..6582979c1ff 100644--- a/test/javascripts/components/d-editor-test.js+++ b/test/javascripts/components/d-editor-test.js@@ -1,4 +1,5 @@import { next } from "@ember/runloop";+import { clearToolbarCallbacks } from "discourse/components/d-editor";import componentTest from "helpers/component-test";import { withPluginApi } from "discourse/lib/plugin-api";import formatTextWithSelection from "helpers/d-editor-helper";@@ -633,6 +634,11 @@ componentTest("emoji", {});this.set("value", "hello world.");},++ afterEach() {+ clearToolbarCallbacks();+ },+async test(assert) {jumpEnd(find("textarea.d-editor-input")[0]);await click("button.emoji");