Is there any way to manually fire the DOMContentLoaded
event?
I'm trying to write a unit-test for some client-side JavaScript which does some stuff on the DOMContentLoaded
event.
The following did not work:
document.dispatchEvent("DOMContentLoaded")
or
document.body.dispatchEvent("DOMContentLoaded")
cancelable: true
is not necessary since theDOMContentLoaded
event on either window or document is not cancelable when it's dispatched by browser, and you may also want to dispatch the window.onload event that is also not cancelable too. – Assonance