Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QUnit autostart

I'm using QUnit to test my JavaScript. I'm also using requirejs. I have test code which looks like this:

QUnit.config.autostart = false;

require(['tests/tests'], function () {
    QUnit.start(); //Tests loaded, run tests
});

This works great in FF (19.0.2 as it happens) but in both Chrome (27) and IE (10), I'm getting a QUnit error:

"pushFailure() assertion outside test context"

Turns out that I don't need the call to QUnit.start in IE and Chrome. Anybody else seen this or have any suggestions as to why?

like image 390
Kevin Jones Avatar asked Mar 30 '13 07:03

Kevin Jones


1 Answers

If anybody else hits this issue I've found a solution. Empirically both Chrome and IE fire QUnit's load event as soon as QUnit is accessed and load calls start. What I've done is this:

<script type="text/javascript" src="qunit-1.11.0.js"></script>
<script type="text/javascript">
    QUnit.config.autostart = false;
</script>
    <script type="text/javascript" data-main="main" src="require.js"></script>

So, load QUnit, set the autostart and then load requirejs

This is messier than setting autostart=false in main.js but it has the benefit of working :)

like image 134
Kevin Jones Avatar answered Nov 14 '22 02:11

Kevin Jones