Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

Practice exercises CHAPTER 6 305


</head>
<body>
<h1 id="qunit-header">QUnit example</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
test markup, will be hidden
<input id="txtResult" type="text" readonly="readonly" /><br />
<input id="txtInput" type="text" /><br />
<button id="btnNumber7">7</button>
<button id="btnNumber8">8</button>
<button id="btnNumber9">9</button><br />
<button id="btnNumber4">4</button>
<button id="btnNumber5">5</button>
<button id="btnNumber6">6</button><br />
<button id="btnNumber1">1</button>
<button id="btnNumber2">2</button>
<button id="btnNumber3">3</button><br />
<button id="btnClear">C</button>
<button id="btnNumber0">0</button>
<button id="btnClearEntry">CE</button><br />
<button id="btnPlus">+</button>
<button id="btnMinus">-</button>
</div>
</body>
</html>
You must modify the tests.js file to use jQuery, calculatorNamespace, and the
Calculator object.


  1. Open the tests.js file.

  2. In the tests.js file, add a reference to the _references.js file and modify the module
    function to call calculatorLibrary.initialize( ) as follows.
    ///
    module('Calculator Test Suite', {
    setup: function () {
    calculatorNamespace.initialize();
    }
    });

  3. Modify the Initialize Test.
    You don’t need to set txtInput and txtResult because the initialize method calls the
    clear method to set these text boxes.

  4. Modify the rest of the method to use jQuery and run the test to see it pass.
    The completed Initialize Test should look like the following.
    test("Initialize Test", function () {
    expect(2);
    var expected = '0';
    equal($('#txtInput').val(), expected, 'Expected value: ' + expected +

Free download pdf