Я хотел бы заявить, что мой код не генерирует никаких возможных ошибок.
Проблема в том, что мой код выполняет операции DOM, которые вызывают асинхронные реакции:
const slot = document.createElement('slot');
myElement.attachShadow({mode:'open'}).appendChild(slot);
// ...
slot.addEventListener('slotchange', function badFunction(){
throw "MyError";
// const observer = new MutationObserver(()=>{});
// observer.observe(null);
});
// ...
it('when input child element is removed, should not throw an error', function() {
function disconnect(){
// this will throw once slotchange is emmited
myElement.removeChild(myElement.firstElementChild);
}
expect(disconnect).not.to.throw();
});
https://how -to-assert-async-throw.glitch.me /
Код aboe проходит тест, даже если ошибка в конечном итоге будет выдана.