remove unused insertBefore function from dom utils

This commit is contained in:
SeinopSys 2022-04-17 14:58:44 +02:00 committed by Luna D
parent 87f37ab8d4
commit efa5092502
No known key found for this signature in database
GPG key ID: 4B1C63448394F688
2 changed files with 0 additions and 45 deletions

View file

@ -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;

View file

@ -51,10 +51,6 @@ export function makeEl<Tag extends keyof HTMLElementTagNameMap>(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<GlobalEventHandlers, 'addEventListener' | 'removeEventListener'> = document): VoidFunction {
const handler: typeof callback = event => {
if (event.button === 0) callback(event);