每天CookBook之JavaScript-064
- 使用jshint验证js
'use strict';
var test1 = "today";
var test2 = "tomorrow";
if(test == tomorrow){
console.log("nope")
}
jshint 064.js
064.js: line 1, col 1, Use the function form of "use strict".
064.js: line 7, col 24, Missing semicolon.
064.js: line 6, col 4, 'test' is not defined.
064.js: line 6, col 12, 'tomorrow' is not defined.
064.js: line 7, col 5, 'console' is not defined.
5 errors
每天CookBook之JavaScript-065
- 使用qunit做单元测试
tests.js
function addAndRound (value1, value2) {
return Math.round(value1 + value2);
}
QUnit.test("testing addAndRound", function(assert){
assert.equal(6, addAndRound(3.55,2.33), "chceking valid");
assert.ok(addAndRound("three", "4.12"), "chceking NaN");
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>065</title>
<link rel="stylesheet" type="text/css" href="qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="qunit.js"></script>
<script src="tests.js"></script>
</body>
</html>