This is a spec to verify that your Mocha Spec Runner page can actually load all its script tags.
Paste it into your Spec Runner page as an inline script, just before mocha.run();
.
Why?
If one of your source scripts fails to load (e.g. due to a malformed URL), you usually don't get any error message. This can cause confusing test failures that are hard to debug.
How it works
It runs through all external script tags in the page, and attempts to reload them over AJAX. If any of them fails to load, this spec will fail (with a message specifying the URL that it couldn't load).
Selectively allowing some script tags to fail
If you have a script tag that you don't mind failing to load in some cases (e.g. /testem.js
, when you are serving your spec runner through something other than Testem's server, such as during grunt test
in a Yeoman webapp project)... just add a data-optional
attribute:
<script src="/testem.js" data-optional></script>