describe('Modals', function () { beforeEach(function () { var templateModal = [ 'Open modal', '' ].join(''); document.body.innerHTML += templateModal; }); afterEach(function () { var linkModal = document.getElementById('linkOpenModal'); var modal = document.getElementById('myModal'); linkModal.parentNode.removeChild(linkModal); modal.parentNode.removeChild(modal); }); it('Modal should fire modalOpen event', function (done) { window.addEventListener('modalOpen', function () { expect(true).toBe(true); done(); }); var link = document.getElementById('linkOpenModal'); var eventTouchEnd = new CustomEvent('touchend', { bubbles: true, cancelable: true }); link.dispatchEvent(eventTouchEnd); }); it('Modal should fire modalClose event', function (done) { var link = document.getElementById('linkOpenModal'); var eventTouchEnd = new CustomEvent('touchend', { bubbles: true, cancelable: true }); window.addEventListener('modalClose', function () { expect(true).toBe(true); done(); }); link.dispatchEvent(eventTouchEnd); var closeLink = document.getElementById('linkCloseModal'); closeLink.dispatchEvent(eventTouchEnd); }); });