使用jslint与qunit保障JS代码质量
使用jslint进行语法和风格的检查,可以预防错误。
vim配置如下:
" jslint map! lint !D:\jsl-0.3.0\jsl.exe -process %
打开的JS文本中:lint便可以运行jslint。
qunit是jquery团队开发的js测试框架,使用很简单。下面是我的项目中用到的一段测试代码:
<script src="qunit-1.12.0.js"></script> <script src="jquery-1.7.2.js"></script> <script src="../jquery.column.picker.js"></script> <script> test( "test basic envirenment", function() { ok(typeof jQuery === 'function', "jQuery is a function"); ok(typeof $("#monthTable").pickout === 'function', "$('#monthTable').pickout is a function"); }); test( "test pickout selector function", function() { throws( function() {$("#monthTable").pickout()}, /parameter/, "raised error message contains 'parameter' when parameter is empty"); ok($.isArray( $("#monthTable").pickout([0, 1, 3]) ), "column index array parameter is ok"); ok($.isArray( $("#monthTable").pickout("th[name=January],th[name=March]") ), "string selector parameter is ok"); }); test( "test pickout show and hide function, compatible to old", function() { $("#monthTable").pickout({picked: [0, 1, 2]}); ok($("#monthTable").find("tr th:eq(0)").is(":visible"), "pickout show and hide ok"); }); </script>
相关推荐
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
firstboy0 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10