QUnit example

A simple example of QUnit tests using JSFiddle

by Trey Hunner

HTML

<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>

JavaScript

var data = {
    ControlPanel: {
        CurrentInOrder: 1
    },
    Questions: [{
        Text: "Do we like to test?"
    }, {
        Text: "Do we have to test?"
    }, {
        Text: "Why do we test?"
    }, {
        Text: "When do we test?"
    }]
};

test("A very simple test of no value", function () {
    ok(1 == "1", "Test passed! (But we didn't test anything)");
});

test("Array should contain four items", function () {
    equal(data.Questions.length, 4, "Pass! - array contains four items");
});