QUnit autostart
Asked Answered
P

1

11

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?

Pantalets answered 30/3, 2013 at 7:37 Comment(0)
P
14

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 :)

Pantalets answered 31/3, 2013 at 17:58 Comment(1)
This also seems to be a good fix: #15922207Veldaveleda

© 2022 - 2024 — McMap. All rights reserved.