I have this fonction that removes an element from the dom
export function removeSlot(component: any, selector: string) {
if (component.querySelectorAll(selector).length > 0) {
component.querySelectorAll(selector).forEach(el => el.remove());
} else {
console.error(`'${selector}' not found in component '${component.tagName.toLowerCase()}'`);
}
}
So far I have this code
describe('delete element', () => {
it('delete the element', function() {
const html = `
<div>
<ol>
<li>
<a href="https://www.example.com/">lorem</a>
</li>
<li>lorem</li>
<li>
<a href="https://www.example.com/">
lorem
</a>
</li>
<li>lorem</li>
</ol>
</div>
`;
document.body.innerHTML = html;
removeSlot(html, 'ol');
expect(document.querySelectorAll('ol').length).toEqual(1);
});
});
I get errors
Any help would be very much appreciated!
Aucun commentaire:
Enregistrer un commentaire