Background Image
Table of Contents Table of Contents
Previous Page  257 / 478 Next Page
Information
Show Menu
Previous Page 257 / 478 Next Page
Page Background

The

test

function defines a test case, a bit like

def test_something(self)

did

in Python. Its first argument is a name for the test, and the second is a function

for the body of the test.

The

equal

function is an assertion; very much like

assertEqual

, it compares

two arguments. Unlike in Python, though, the message is displayed both for

failures and for passes, so it should be phrased as a positive rather than a negative.

Why not try changing those arguments to see a deliberate failure?

Using jQuery and the Fixtures Div

Let’s get a bit more comfortable with what our testing framework can do, and start using

a bit of jQuery

If you’ve never seen jQuery before, I’m going to try and explain it as

we go, just enough so that you won’t be totally lost; but this isn’t a

jQuery tutorial. You may find it helpful to spend an hour or two

investigating jQuery at some point during this chapter.

Let’s add jQuery to our scripts, and a few elements to use in our tests:

lists/static/tests/tests.html.

<div

id=

"qunit-fixture"

></div>

<form>

<input

name=

"text"

/>

<div

class=

"has-error"

>

Error text

</div>

</form>

<script

src=

"http://code.jquery.com/jquery.min.js

"

></script>

<script

src=

"qunit.js"

></script>

<script>

/*global $, test, equal */

test("smoke test", function () {

equal($('.has-error').is(':visible'), true); //

$('.has-error').hide(); //

equal($('.has-error').is(':visible'), false); //

});

</script>

The

<form>

and its contents are there to represent what will be on the real list

page.

Using jQuery and the Fixtures Div

|

229