I am using angular 8 and Jest for unit testing. I have added a listener for 'transitionend' on the element, but I haven't been able to figure out how to trigger/mock the transitionend event with Jest
this.animatedElement.nativeElement.addEventListener('transitionend', () => {
this.transitionEnded = true;
});
I am trying to create a unit test that tests this.transitionEnded is true
Use this helper function to trigger any event:
function triggerTransitionEnd(element) {
let event = document.createEvent("Event");
event.initEvent("transitionend", true, true);
element.dispatchEvent(event);
}
And then in your test use it like so:
test("Some description here", () => {
const popup = document.getElementById("popup");
triggerTransitionEnd(popup);
expect(popup.classList.contains("show")).toBeFalsy();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With