7. QUnit
QUnit is a powerful, easy-to-use JavaScript
unit test suite. It's used by the jQuery,
jQuery UI and jQuery Mobile projects and is
capable of testing any generic JavaScript
code, including itself!
http://qunitjs.com
Tuesday, 18 September 12
9. Example
Validate Telephone Number
Tuesday, 18 September 12
10. QUnit : HTML test suite
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Example</title>
<link rel="stylesheet" href="/resources/qunit.css">
</head>
<body>
<div id="qunit"></div>
<script src="/resources/qunit.js"></script>
<script src="/resources/tests.js"></script>
</body>
</html>
Tuesday, 18 September 12
11. QUnit: Add a test
// tests.js
// Test
module("isPhoneNumber");
test("Wrong number", function () {
equal(isPhoneNumber("abcdefg"), false, "All alphabet");
});
Tuesday, 18 September 12
12. QUnit: Run all test and
see if the new one fails
Tuesday, 18 September 12
13. QUnit: Write some code
// Code Under Test
isPhoneNumber = function(a) {
return false;
}
// Test
module("isPhoneNumber");
test("Wrong number", function () {
equal(isPhoneNumber("abcdefg"), false, "All alphabet");
});
Tuesday, 18 September 12