8
0

cleanup.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document */
  6. /**
  7. * Removes all the `.ck-body` elements available in the DOM.
  8. *
  9. * It is commonly used to cleanup after editors that test editor crashes.
  10. *
  11. * See https://github.com/ckeditor/ckeditor5/issues/6018 for more details.
  12. */
  13. export function removeEditorBodyOrphans() {
  14. for ( const bodyOrphan of document.querySelectorAll( '.ck-body' ) ) {
  15. bodyOrphan.remove();
  16. }
  17. }
  18. /**
  19. * Searches for orphaned editors based on DOM.
  20. *
  21. * This is useful if in your tests you have no access to editor, instance because editor
  22. * creation method doesn't complete in a graceful manner.
  23. */
  24. export function destroyEditorOrphans() {
  25. const promises = [];
  26. for ( const editableOrphan of document.querySelectorAll( '.ck-editor__editable' ) ) {
  27. if ( editableOrphan.ckeditorInstance ) {
  28. promises.push( editableOrphan.ckeditorInstance.destroy() );
  29. }
  30. }
  31. return Promise.all( promises );
  32. }