diff --git a/assets/js/utils/__tests__/dom.spec.ts b/assets/js/utils/__tests__/dom.spec.ts index aed07f3f..d0c65098 100644 --- a/assets/js/utils/__tests__/dom.spec.ts +++ b/assets/js/utils/__tests__/dom.spec.ts @@ -5,7 +5,6 @@ import { escapeCss, escapeHtml, hideEl, - insertBefore, makeEl, onLeftClick, removeEl, @@ -297,46 +296,6 @@ describe('DOM Utilities', () => { }); }); - describe('insertBefore', () => { - it('should insert the new element before the existing element', () => { - const mockParent = document.createElement('p'); - const mockExisingElement = document.createElement('span'); - mockParent.appendChild(mockExisingElement); - const mockNewElement = document.createElement('strong'); - - insertBefore(mockExisingElement, mockNewElement); - - expect(mockParent.children).toHaveLength(2); - expect(mockParent.children[0].tagName).toBe('STRONG'); - expect(mockParent.children[1].tagName).toBe('SPAN'); - }); - - it('should insert between two elements', () => { - const mockParent = document.createElement('p'); - const mockFirstExisingElement = document.createElement('span'); - const mockSecondExisingElement = document.createElement('em'); - mockParent.appendChild(mockFirstExisingElement); - mockParent.appendChild(mockSecondExisingElement); - const mockNewElement = document.createElement('strong'); - - insertBefore(mockSecondExisingElement, mockNewElement); - - expect(mockParent.children).toHaveLength(3); - expect(mockParent.children[0].tagName).toBe('SPAN'); - expect(mockParent.children[1].tagName).toBe('STRONG'); - expect(mockParent.children[2].tagName).toBe('EM'); - }); - - it('should NOT fail if there is no parent', () => { - const mockParent = document.createElement('p'); - const mockNewElement = document.createElement('em'); - - expect(() => { - insertBefore(mockParent, mockNewElement); - }).not.toThrow(); - }); - }); - describe('onLeftClick', () => { let cleanup: VoidFunction | undefined; diff --git a/assets/js/utils/dom.ts b/assets/js/utils/dom.ts index b115b74c..34bfe02b 100644 --- a/assets/js/utils/dom.ts +++ b/assets/js/utils/dom.ts @@ -51,10 +51,6 @@ export function makeEl(tag: Tag, attr?: return el; } -export function insertBefore(existingElement: HTMLElement, newElement: HTMLElement) { - existingElement.parentNode?.insertBefore(newElement, existingElement); -} - export function onLeftClick(callback: (e: MouseEvent) => boolean | void, context: Pick = document): VoidFunction { const handler: typeof callback = event => { if (event.button === 0) callback(event);