HTML and CSS Reference
In-Depth Information
This method of working really helps you to write much cleaner code, as your
code will now be written to satisfy only the expected output.
Writing Your First Unit Test
You can either choose to write your own unit-testing framework or use one
that's readily available. The choice for this topic is QUnit. It has been developed
by the jQuery community and has regular updates. Not only this, but it can be
run from the browser, or optionally, can be run from the command line using a
program called PhantomJS.
To set up a QUnit unit test for the calculator, first create a new file called
calculator.html in the tests folder containing the following HTML.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>calculator unit tests</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-
scale=1.0; user-scalable=0; target-densitydpi=device-dpi;"/>
<!-- Include the latest QUnit JavaScript file -->
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<!-- Include calculator JavaScript file -->
<script src="../app/calculator.js"></script>
<!-- Include the latest QUnit CSS file -->
<link href=" http://code.jquery.com/qunit/qunit-git.css" re l="stylesheet"
type="text/css" />
</head>
<body>
<h1 id="qunit-header">calculator unit tests</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"><!-- If you have DOM that needs to be manipulated,
this is where it should go --></div>
 
Search WWH ::




Custom Search