Figure 13-2. One of the two tests is failing
What’s happening here is that the first test hides the error div, so when the second test
runs, it starts out invisible.
QUnit tests do not run in a predictable order, so you can’t rely on the
first test running before the second one.
We need some way of tidying up between tests, a bit like
setUp
and
tearDown
, or like
the Django test runner would reset the database between each test. The
qunit-
fixture
div is what we’re looking for. Move the form in there:
lists/static/tests/tests.html.
<div
id=
"qunit"
></div>
<div
id=
"qunit-fixture"
>
<form>
<input
name=
"text"
/>
<div
class=
"has-error"
>
Error text
</div>
</form>
</div>
<script
src=
"http://code.jquery.com/jquery.min.js"
></script>
As you’ve probably guessed, jQuery resets the content of the fixtures div before each
test, so that gets us back to two neatly passing tests:
Using jQuery and the Fixtures Div
|
231