diff options
Diffstat (limited to 'spec/frontend/content_editor/test_utils.js')
-rw-r--r-- | spec/frontend/content_editor/test_utils.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/frontend/content_editor/test_utils.js b/spec/frontend/content_editor/test_utils.js index 84eaa3c5f44..dde9d738235 100644 --- a/spec/frontend/content_editor/test_utils.js +++ b/spec/frontend/content_editor/test_utils.js @@ -142,3 +142,23 @@ export const triggerMarkInputRule = ({ tiptapEditor, inputRuleText }) => { f(view, selection.from, inputRuleText.length + 1, inputRuleText), ); }; + +/** + * Executes an action that triggers a transaction in the + * tiptap Editor. Returns a promise that resolves + * after the transaction completes + * @param {*} params.tiptapEditor Tiptap editor + * @param {*} params.action A function that triggers a transaction in the tiptap Editor + * @returns A promise that resolves when the transaction completes + */ +export const waitUntilNextDocTransaction = ({ tiptapEditor, action }) => { + return new Promise((resolve) => { + const handleTransaction = () => { + tiptapEditor.off('update', handleTransaction); + resolve(); + }; + + tiptapEditor.on('update', handleTransaction); + action(); + }); +}; |