DEV: prevents toolbar callbacks to leak between tests (#9403)

DEV: prevents toolbar callbacks to leak between tests (#9403)

diff --git a/app/assets/javascripts/discourse/components/d-editor.js b/app/assets/javascripts/discourse/components/d-editor.js
index b83b667..199266c 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.js
index 131de74..6582979 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");

GitHub sha: 058506bb

This commit appears in #9403 which was merged by jjaffeux.