{"id":3170,"date":"2013-04-09T22:11:18","date_gmt":"2013-04-09T14:11:18","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3170"},"modified":"2018-01-02T02:45:58","modified_gmt":"2018-01-01T18:45:58","slug":"qunit-javascript-unit-test-%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2013\/04\/qunit-javascript-unit-test-%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95\/","title":{"rendered":"\u8fb9\u8bd1\u8fb9\u5b66-QUnit\u4e0b\u7684JavaScript\u81ea\u52a8\u5316\u5355\u5143\u6d4b\u8bd5"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3170\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=3170<\/a><\/p>\n<style type=\"text\/css\">\/* Chili -- html *\/\n.html__doctype { color: #CC6600; }\n.html__ie_style { color: DarkSlateGray; font-weight: bold; }\n.html__comment { color: #4040c2; }\n.html__tag_start { color: navy; font-weight: bold; }\n.html__tag_end { color: navy; }\n.html__entity { color: blue; }\n.html__attr_name { color: green; }\n.html__attr_value { color: maroon; }<\/style>\n<style type=\"text\/css\">\/* Chili -- js *\/\n.js__ml_comment { color: gray; }\n.js__sl_comment { color: green; }\n.js__string { color: teal; }\n.js__num { color: red; }\n.js__reg_exp { color: maroon; }\n.js__brace { color: red; font-weight: bold; }\n.js__statement { color: navy; font-weight: bold; }\n.js__error { color: Coral; }\n.js__object { color: DeepPink; }\n.js__property { color: Purple; font-weight: bold; }\n.js__function { color: olive; }\n.js__operator { color: RoyalBlue; font-weight: bold; }\n.js__liveconnect { text-decoration: overline; }\n.CodeHighlighter pre{margin-top: 0;}<\/style>\n<div id=\"link\" class=\"mt10\">\n\u53c2\u8003\u539f\u6587\uff1a<a href=\"http:\/\/msdn.microsoft.com\/en-us\/magazine\/gg749824.aspx?from=zhangxinxu.com\">Automating JavaScript Testing with QUnit<\/a><br \/>\n\u539f\u6587\u4f5c\u8005\uff1aJ\u00f6rn Zaefferer\n<\/div>\n<div style=\"padding:3px; background-color:#eee; margin-top:20px;\">\n<div style=\"border:1px solid #cacaca;\">\n<div style=\"background-color:#eee; padding:10px; background-image:linear-gradient(#FAFAFA, #EAEAEA);\">\u53c2\u6742\u8bd1\u8005\u5410\u69fd\u7684\u6b63\u6587<\/div>\n<div style=\"padding:20px; background-color:#fff;\">\n<h3>\u4e00\u3001\u5f97\u4e86\u5f00\u5934\u4e0d\u5410\u69fd\u4e0d\u8212\u670d\u7684\u75c5<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u6211\u6628\u665a\u975e\u4e00\u4eba\u53bb\u770b\u300a\u5317\u4eac\u5907\u80ce\u897f\u96c5\u56fe\u300b\u4e86\uff0c\u8fd8\u4e0d\u9519\u54e6~<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/12.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u64e6\uff0c\u53c8\u6765\u4e86\uff0c\u4f19\u8ba1\u3002\u6211\u4eec\u5f88\u5fd9\u7684\uff0c\u6280\u672f\u4e0d\u76f8\u5e72\u7684\u5410\u69fd\u7559\u7740\u5bf9\u4f60\u5ab3\u5987\u8bb2\u5427\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/103.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u90b5\u745e\u554a\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/106.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u5982\u679c\u201c\u626b\u745e\u201d\u6709\u7528\uff0c\u90a3\u8fd8\u8981\u8b66\u5bdf\u53d4\u53d4\u5e72\u561b\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/193.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> (\u2299o\u2299)\u2026<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/191.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u4ee5\u524d\u66fe\u542c\u8fc7\u201c\u6d4b\u8bd5\u9a71\u52a8\u7684JS\u5f00\u53d1\u201d\u5206\u4eab\uff0c\u81f3\u4e8e\u5177\u4f53\u5185\u5bb9\u662f\u4ec0\u4e48\uff0c\u5df2\u7ecf\u5fd8\u5f97\u4e00\u5e72\u4e8c\u51c0\uff0c\u4e0d\u8fc7\u77e5\u9053\u4e86\u8fd9\u4e2a\u4e1c\u897f\uff0c\u5c31\u662f\u4e0d\u9519\u7684\u6536\u83b7\u3002\u7ecf\u5e38\u770b\u5230\u542c\u5230\u201cJS\u5355\u5143\u6d4b\u8bd5\u201d\uff0c\u81f3\u4e8e\u5177\u4f53\u600e\u4e48\u64cd\u4f5c\uff0c\u4e5f\u662f\u4e0d\u5f97\u800c\u77e5\uff0c\u56e0\u4e3a\u5b9e\u9645\u7684\u5de5\u4f5c\u5e76\u672a\u4f7f\u7528\u4e4b\u3002\u6628\u5929\uff0c\u770b\u5230\u4e86\u4e00\u4f4d\u524d\u7aef\u725b\u4eba\u8089\u8eab\u7ffb\u5899\u627e\u5de5\u4f5c\u7684\u7ecf\u5386\uff0c\u5176\u4e2d\u5c31\u63d0\u5230\uff0c\u5176\u56de\u7b54Facebook\u7684\u9762\u8bd5\u9898\u65f6\u5019\u628a\u5355\u5143\u6d4b\u8bd5\u4ee3\u7801\u4e00\u5e76\u53d1\u8fc7\u53bb\u4e86\u3002<\/p>\n<p style=\"text-indent:27px;\">\u5988\u5988\u5343\u53e5\u5520\u53e8\u4e0d\u53ca\u670b\u53cb\u4e00\u8bed\u70b9\u62e8\uff0c\u8fd9\u91cc\u7684\u201c\u5355\u5143\u6d4b\u8bd5\u201d\u4e00\u4e0b\u5b50\u6233\u4e2d\u4e86\u6211\u7684\u5c0f\u5c0f\u795e\u7ecf\u3002\u4e8e\u662f\uff0c\u4eca\u5929\uff0c\u5de5\u4f5c\u4e4b\u4f59\uff0c\u5f00\u59cb\u63a5\u89e6&#8221;JS\u5355\u5143\u6d4b\u8bd5&#8221;\u76f8\u5173\u7684\u4e00\u4e9b\u5185\u5bb9\u3002\u5b66\u4e60\u76ee\u6807\u4e3a\uff0c\u8981\u5bf9\u201c\u5355\u5143\u6d4b\u8bd5\u201d\u8981\u8db3\u591f\u611f\u6027\u6574\u4f53\u7684\u8ba4\u8bc6\uff0c\u6e05\u695a\u5982\u679c\u5728\u81ea\u5df1\u9879\u76ee\u4e2d\u4f7f\u7528\u5355\u5143\u6d4b\u8bd5\uff0c\u8be5\u600e\u4e48\u505a\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u54ea\u4e9b\u963b\u788d\u3002<\/p>\n<p style=\"text-indent:27px;\">\u76ee\u524d\uff0c\u6709\u4e0d\u5c11\u522b\u4eba\u8bf4\u4e0d\u9519\u7684JS\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\uff0c\u6bd4\u65b9\u8bf4\u2026\u2026\u989d~\u6211\u53bb\uff0c\u521a\u90a3\u4e2a\u7f51\u9875\u88ab\u6211close\u6389\u4e86\uff0c\u5927\u5bb6\u81ea\u5df1\u641c\u4e0b\u5427\u3002\u5176\u4e2d\u6709\u4e00\u4e2a\u662fQUnit, \u8c8c\u4f3c\u662fjQuery\u56e2\u961f\u6363\u9f13\u7684\uff08\u5e76\u4e0d\u4f9d\u8d56jQuery\uff09\u3002\u672c\u6587\u5c31\u662f\u8981\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528QUnit\u505a\u5355\u5143\u6d4b\u8bd5\u3002\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u9009\u62e9QUnit, \u90a3\u662f\u56e0\u4e3a\u636e\u8bf4QUnit\u65b0\u624b\u6700\u597d\u4e0a\u624b\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u53ef\u5426\u8bb2\u8bb2\u5355\u5143\u6d4b\u8bd5\u7684\u5fc5\u8981\u6027\u5462\uff1f <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/32.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u8fd9\u4e2a\u561b\uff0c\u7f51\u4e0a\u7684\u8bf4\u6cd5\u662f\uff1a\u5929\u8d50\u4e00\u53cc\u91d1\u949b\u72d7\u773c\uff0c\u7acb\u663e\u81ed\u866b\u5f97\u745f\u5634\u8138<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/117.gif\" align=\"absmiddle\">\u3002\u6211\u81ea\u5df1\u5c1a\u672a\u6df1\u5165\u5c1d\u8bd5\uff0c\u5355\u5143\u6d4b\u8bd5\u662f\u5426\u6709\u5fc5\u8981\u6211\u5e76\u4e0d\u786e\u5b9a\uff0c\u6211\u4f1a\u5728\u6587\u7ae0\u6700\u540e\u56de\u7b54\u6b64\u95ee\u9898\u3002<\/p>\n<h3>\u4e8c\u3001QUnit\u662f\u4ec0\u4e48\u6765\u8def\uff1f<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> QUnit\u662f\u4ec0\u4e48\u6765\u8def\uff1f <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/32.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> <a href=\"http:\/\/docs.jquery.com\/QUnit\">QUnit<\/a>\u51fa\u751f\u4e8e2008\u5e745\u6708\uff0c\u8d70\u51fatestrunner\u5d4c\u5165jQuery\u6838\u5fc3\u5b58\u50a8\u5e93\u3002\u4ece\u6b64\uff0c\u5b83\u6709\u4e86\u81ea\u5df1\u7684\u540d\u79f0\u548c\u6587\u6863\u548c\u4e00\u4e2a\u5b89\u653e\u4ee3\u7801\u7684\u65b0\u5bb6\u30022009\u5e74\u672bQUnit\u88ab\u91cd\u6784\uff0c\u72ec\u7acb\u4e8ejQuery\uff0c\u4f7f\u5176\u53ef\u7528\u4e8e\u6d4b\u8bd5\u5404\u79cd\u5404\u6837\u7684JavaScript\u6846\u67b6\u548c\u5e94\u7528\u7a0b\u5e8f\u3002QUnit\u5ba3\u79f0\u5176\u65b9\u6cd5\u73b0\u5728\u9075\u5faaCommonJS\u7ef4\u62a4\u89c4\u8303\u3002\u867d\u7136QUnit\u53ef\u4ee5\u8fd0\u884c\u5728\u670d\u52a1\u5668\u7aef\u6216\u547d\u4ee4\u884c\u73af\u5883\u4e2d\uff0c\u4f46\u5b83\u6700\u6709\u6548\u7684\u662f\u6d4b\u8bd5\u6d4f\u89c8\u5668\u4e2d\u7684JavaScript\u3002<\/p>\n<p style=\"text-indent:27px;\">\u5b98\u65b9\u81ea\u7136\u6361\u597d\u8bdd\u8bb2\uff0c\u8bf4QUnit\u662f\u4e2a\u5f3a\u5927\u7b80\u5355\u6613\u7528\u7684JavaScript\u6d4b\u8bd5\u6846\u67b6\u3002jQuery, jQuery UI, jQuery Mobile\u90fd\u662f\u4f7f\u7528Qunit\u505a\u5355\u5143\u6d4b\u8bd5\u7684\uff0c\u751a\u81f3\u5305\u62ec\u5b83\u81ea\u5df1\u3002\u6211\u6293\u4e86\u6293\u5934\u53d1\u65e5\u6e10\u7a00\u5c11\u7684\u8111\u888b\u74dc\uff0c\u51b3\u5b9a\u81ea\u5df1\u4eb2\u81ea\u5b9e\u8df5\uff0c\u9a8c\u8bc1\u662f\u5426\u5982\u5b98\u7f51\u4e0a\u6240\u8bf4\u7684\u5f3a\u5927\u7b80\u5355\u6613\u7528\u3002<\/p>\n<h3>\u4e09\u3001\u6ca1\u9519\uff0c\u662fHello World!<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u63a5\u89e6\u65b0\u7684\u8bed\u8a00\u7b49\uff0c\u8dd1\u901a\u7684\u7b2c\u4e00\u4e2a\u4f8b\u5b50\u662fHello World! \u6bd5\u7adf\u662f\u7ffb\u8bd1\uff0c\u8fd9\u91cc\u4e5f\u4fd7\u5957\u4e00\u628a\u3002\u5728\u6d4b\u8bd5\u4ee3\u7801\u5c55\u793a\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u94fe\u63a5\u51e0\u4e2a\u9759\u6001\u8d44\u6e90\uff0c\u4e0d\u96be\u60f3\u5230\uff0c\u662fQUnit\u7684JS\u8d44\u6e90\u4ee5\u53caCSS\u6837\u5f0f\u8d44\u6e90\u3002\u76ee\u524d\u7248\u672c\u662f<code>1.11.0<\/code>. \u60a8\u53ef\u4ee5\u70b9\u51fb\u4e0b\u9762\u7684\u94fe\u63a5\u4e0b\u8f7d\uff1a<\/p>\n<ul>\n<li><a href=\"http:\/\/code.jquery.com\/qunit\/qunit-1.11.0.js\" target=\"_blank\">qunit-1.11.0.js<\/a><\/li>\n<li><a href=\"http:\/\/code.jquery.com\/qunit\/qunit-1.11.0.css\" target=\"_blank\">qunit-1.11.0.css<\/a><\/li>\n<\/ul>\n<p style=\"text-indent:27px;\">\u4e5f\u652f\u6301<a href=\"https:\/\/npmjs.org\/package\/qunitjs\">npm\u5b89\u88c5<\/a>\u3002\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<div class=\"zxx_code\" style=\"margin-left:27px;\">\n<pre>npm install qunitjs<\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u5982\u679c\u60a8\u61d2\u5f97\u4e0b\u6b21\uff0c\u76f4\u63a5include\u9759\u6001\u8d44\u6e90\u4e5f\u662f\u53ef\u4ee5\u7684\uff0c\u6709CDN\uff0c\u4ee3\u7801\u5982\u4e0b\uff0c\u5b98\u65b9\u622a\u56fe\u5982\u4e0b\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\" style=\"margin-left:27px;\">\n<pre>&lt;link rel=\"stylesheet\" href=\"http:\/\/code.jquery.com\/qunit\/qunit-1.11.0.css\" \/>\n&lt;script src=\"http:\/\/code.jquery.com\/qunit\/qunit-1.11.0.js\">&lt;\/script><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-08_163839.png\" height=\"157\" alt=\"\u8c03\u7528\u5730\u5740\u622a\u56fe\"><\/p>\n<p style=\"text-indent:27px;\">\u70ed\u8eab\u5b8c\u6bd5\uff0c\u716e\u9752\u86d9\u5f00\u59cb\u5566~~<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/29.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u5982\u4e0b\u7b80\u5355\u57fa\u672c\u7684\u6d4b\u8bd5\u4ee3\u7801\uff1a<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\"><span class=\"html__doctype\">&lt;!DOCTYPE&nbsp;html&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;link<\/span>&nbsp;<span class=\"html__attr_name\">rel<\/span>=<span class=\"html__attr_value\">\"stylesheet\"<\/span>&nbsp;<span class=\"html__attr_name\">href<\/span>=<span class=\"html__attr_value\">\"qunit.css\"<\/span><span class=\"html__tag_start\">&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;script<\/span>&nbsp;<span class=\"html__attr_name\">src<\/span>=<span class=\"html__attr_value\">\"qunit.js\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/script&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;script<\/span><span class=\"html__tag_start\">&gt;<\/span><\/li><li style=\"\">test(\"hello\",&nbsp;function()&nbsp;{<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;ok(true,&nbsp;\"world\");<\/li><li style=\"\">});<\/li><li style=\"\"><span class=\"html__tag_end\">&lt;\/script&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;h1<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-header\"<\/span><span class=\"html__tag_start\">&gt;<\/span>QUnit&nbsp;Hello&nbsp;World<span class=\"html__tag_end\">&lt;\/h1&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;h2<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-banner\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/h2&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;ol<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-tests\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/ol&gt;<\/span><\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u7ea6\u7684\u6d4b\u8bd5\u6848\u4f8b\u3002\u5b9a\u4e49\u4e86\u6587\u6863\u7c7b\u578b\uff0c\u5305\u542b\u4e86QUnit\u9700\u8981\u7684CSS\u4ee5\u53caJS\uff0c\u5b9a\u4e49\u4e86\u53e6\u5916\u4e00\u4e2a<code>script<\/code>\u5143\u7d20\uff0c<code>script<\/code>\u4e2d\u4e3a\u5355\u4e2aQUnit\u6d4b\u8bd5\u4ee3\u7801\uff0c\u7136\u540e\u9875\u9762\u4e0a\u8fd8\u6709\u4e00\u6bb5\u7528\u6765\u8f93\u51fa\u7ed3\u679c\u7684\u6807\u8bb0\uff08\u5982<code>&lt;h2 id=\"qunit-banner\"&gt;<\/code>\uff09\u3002<code>test()<\/code>\u51fd\u6570\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u53eb<code>\"hello\"<\/code>\u7684\u6d4b\u8bd5\u3002\u4e00\u65e6\u9875\u9762\u8f7d\u5165\u5b8c\u6bd5\uff0cQUnit\u5c31\u4f1a\u8fd0\u884c<code>test()<\/code>\u3002\u4f20\u7ed9<code>test()<\/code>\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u51fd\u6570\uff0c\u8fd9\u624d\u662f\u6d4b\u8bd5\u7684\u771f\u8eab\uff0c\u6b64\u5904\u4e3a<code>ok()<\/code>\u65b9\u6cd5\u3002<code>ok()<\/code>\u65b9\u6cd5\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u7528\u6765\u8868\u660e\u6d4b\u8bd5\u662f\u901a\u8fc7\u4e86\u5462\u8fd8\u662f\u6ca1\u6709\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5219\u662f\u9700\u8981\u8f93\u51fa\u7684\u4fe1\u606f\u3002\u4e0a\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a<code>true<\/code>, \u56e0\u6b64\uff0c\u5c31\u7b97\u6307\u9e7f\u4e3a\u9a6c\u4e5f\u662f\u901a\u8fc7\u7684\uff0c\u5b9e\u9645\u4e0a\u6ca1\u505a\u4efb\u4f55\u5b9e\u8d28\u6027\u7684\u6d4b\u8bd5\u3002<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/98.gif\" align=\"absmiddle\"><\/p>\n<p style=\"text-indent:27px;\">\u5982\u679c\u6211\u4eec\u5728\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884c\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u5219\u4f1a\u5982\u4e0b\u9762\u8fd9\u6a21\u6837\uff1a<\/p>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-08_174507.png\" alt=\"pass\u7ed3\u679c\u793a\u610f\" height=\"140\"><\/p>\n<p style=\"text-indent:27px;\">\u622a\u56fe\u4e3a\u865a\uff0c\u4eb2\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-1.html\" target=\"_blank\" class=\"a_link\">true\u4e0b\u6b7b\u6d3bpassed demo<\/a><\/p>\n<p style=\"text-indent:27px;\">\u663e\u7136\uff0c\u5982\u679c\u662f\uff1a<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">test(<span class=\"js__string\">\"hello\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;ok(false,&nbsp;<span class=\"js__string\">\"world\"<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u5219\u6c38\u8fdc\u4e0d\u4f1a\u901a\u8fc7\u7684\uff1a<\/p>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-08_181731.png\" alt=\"\u6d4b\u8bd5\u4e0d\u901a\u8fc7\"><\/p>\n<p style=\"text-indent:27px;\">\u4ece\u622a\u56fe\u770b\u4ee5\u770b\u51fa\uff0c<code>\"word\"<\/code>\u8fd9\u4e2a\u9519\u8bef\u4fe1\u606f\u8f93\u51fa\u6765\u4e86\uff08\u9a8c\u8bc1\u4e86<code>ok()<\/code>\u7b2c\u4e8c\u4e2a\u53c2\u6570\u7684\u529f\u80fd\uff09\uff0c\u540c\u65f6\u8fd8\u6807\u6ce8\u4e86\u9519\u8bef\u4ee3\u7801\u7684\u4f4d\u7f6e\u3002<\/p>\n<p style=\"text-indent:27px;\">\u622a\u56fe\u4e3a\u865a\uff0c\u4eb2\u89c1\u4e3a\u5b9e, too\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-2.html\" target=\"_blank\" class=\"a_link\">false\u4e0b\u6b7b\u6d3bfailed demo<\/a><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u6709\u70b9\u6837\u5b50\uff0c\u4e0b\u9762\u662f\u4e0d\u662f\u8be5\u6765\u70b9\u771f\u683c\u7684\u5566\u3002<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/29.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> Bingong! \u606d\u559c\u4f60\uff0c\u4f60\u90fd\u4f1a\u62a2\u7b54\u5566\uff01<\/p>\n<h3>\u4e09\u3001\u52a8\u771f\u683c\u7684QUnit\u6d4b\u8bd5<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u53ea\u559d\u6c64\u4e0d\u5403\u8089\uff0c\u5a49\u541b\u4e5f\u4f1a\u76b1\u7709\u5934\u3002\u56e0\u6b64\uff0c\u6765\u4e2a\u66f4\u52a0\u5b8c\u6574\u7684\u4f8b\u5b50\u54c8\uff1a<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\"><span class=\"html__doctype\">&lt;!DOCTYPE&nbsp;html&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;html<\/span><span class=\"html__tag_start\">&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;head<\/span><span class=\"html__tag_start\">&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;title<\/span><span class=\"html__tag_start\">&gt;<\/span>QUnit\u6d4b\u8bd5<span class=\"html__tag_end\">&lt;\/title&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;link<\/span>&nbsp;<span class=\"html__attr_name\">rel<\/span>=<span class=\"html__attr_value\">\"stylesheet\"<\/span>&nbsp;<span class=\"html__attr_name\">href<\/span>=<span class=\"html__attr_value\">\"qunit.css\"<\/span><span class=\"html__tag_start\">&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;script<\/span>&nbsp;<span class=\"html__attr_name\">src<\/span>=<span class=\"html__attr_value\">\"qunit.js\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/script&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;script<\/span>&nbsp;<span class=\"html__attr_name\">src<\/span>=<span class=\"html__attr_value\">\"tests.js\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/script&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_end\">&lt;\/head&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_start\">&lt;body<\/span><span class=\"html__tag_start\">&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;h1<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-header\"<\/span><span class=\"html__tag_start\">&gt;<\/span>QUnit\u6d4b\u8bd5<span class=\"html__tag_end\">&lt;\/h1&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;h2<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-banner\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/h2&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;div<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-testrunner-toolbar\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/div&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;h2<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-userAgent\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/h2&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;ol<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-tests\"<\/span><span class=\"html__tag_start\">&gt;<\/span><span class=\"html__tag_end\">&lt;\/ol&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;div<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-fixture\"<\/span><span class=\"html__tag_start\">&gt;<\/span>\u6d4b\u8bd5\u6807\u8bb0<span class=\"html__tag_end\">&lt;\/div&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_end\">&lt;\/body&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_end\">&lt;\/html&gt;<\/span><\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u4e0e\u4e4b\u524d\u4ee3\u7801\u4e0d\u540c\u7684\u662f\uff0c\u8fd9\u91cc\u591a\u4e86\u4e2a<code>tests.js<\/code>, \u4ee5\u53caHTML\u90e8\u5206\u6709\u4e86\u66f4\u591a\u7684\u6807\u8bb0\uff0c\u5982<code>&lt;h2 id=\"qunit-userAgent\"&gt;<\/code>\u7b49\u3002<code>tests.js<\/code>\u4e2d\u5185\u5bb9\u4e3a\uff1a<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\"><span class=\"js__operator\">function<\/span>&nbsp;format(string,&nbsp;values)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">for<\/span>&nbsp;(<span class=\"js__statement\">var<\/span>&nbsp;key&nbsp;<span class=\"js__operator\">in<\/span>&nbsp;values)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;=&nbsp;string.replace(<span class=\"js__operator\">new<\/span>&nbsp;<span class=\"js__object\">RegExp<\/span>(<span class=\"js__string\">\"\\{\"<\/span>&nbsp;+&nbsp;key&nbsp;+&nbsp;<span class=\"js__string\">\"}\"<\/span>),&nbsp;values[key]);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">return<\/span>&nbsp;string;<\/li><li style=\"\"><span class=\"js__brace\">}<\/span><\/li><li style=\"\">&nbsp;<\/li><li style=\"\">test(<span class=\"js__string\">\"basics\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">var<\/span>&nbsp;values&nbsp;=&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name:&nbsp;<span class=\"js__string\">\"World\"<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;equal(&nbsp;format(<span class=\"js__string\">\"Hello,&nbsp;{name}\"<\/span>,&nbsp;values),&nbsp;<span class=\"js__string\">\"Hello,&nbsp;World\"<\/span>,&nbsp;<span class=\"js__string\">\"\u5355\u4e2a\u5339\u914d\"<\/span>&nbsp;);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;equal(&nbsp;format(<span class=\"js__string\">\"Hello,&nbsp;{name},&nbsp;how&nbsp;is&nbsp;{name}&nbsp;today?\"<\/span>,&nbsp;values),<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__string\">\"Hello,&nbsp;World,&nbsp;how&nbsp;is&nbsp;World&nbsp;today?\"<\/span>,&nbsp;<span class=\"js__string\">\"\u591a\u4e2a\u5339\u914d\"<\/span>&nbsp;);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u4e0a\u9762\u4ee3\u7801\u8981\u505a\u7684\u4e8b\u60c5\u4e0d\u96be\u7406\u89e3\uff0c<code>format<\/code>\u51fd\u6570\u7684\u529f\u80fd\u5c31\u662f\u6a21\u677fHTML\u66ff\u6362\u6280\u672f\uff0cMVC\u7684\u57fa\u7840\u4e4b\u4e00\u3002<\/p>\n<p style=\"text-indent:27px;\">\u8fd9\u91cc\u4f7f\u7528\u7684\u662f<code>equal()<\/code>\u8fdb\u884c\u6d4b\u8bd5\uff0c<code>equal()<\/code>\u65b9\u6cd5\u4f5c\u7528\u662f\u505a\u6bd4\u5bf9\uff0c\u5982\u4f55\u6bd4\u5bf9\u6cd5\u5462\uff1f\u5f88\u7b80\u5355\uff0c\u4f7f\u7528JavaScript\u7684<code>\"==\"<\/code>\u64cd\u4f5c\u7b26\u6bd4\u5bf9\u5176\u524d\u4e24\u4e2a\u53c2\u6570\u3002\u5176\u4e2d\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u5b9e\u9645\u7684\u503c\uff0c\u672c\u4f8b\u5b50\u5c31\u662f<code>format()<\/code>\u7684\u8fd4\u56de\u503c\uff1b\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u6211\u4eec\u671f\u671b\u5f97\u5230\u7684\u503c\uff0c\u683c\u5f0f\u5316\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p style=\"text-indent:27px;\">OK, \u7ed3\u679c\u5230\u5e95\u5982\u4f55\u5462\uff1f\u6211\u4eec\u5148\u770b\u622a\u56fe\u4e00\u89c8\u7a76\u7adf\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_101806.png\" alt=\"\u591a\u5339\u914d\u4e0d\u901a\u8fc7\" height=\"333\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u54c7\u585e\uff0c\u597d\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u63d0\u793a\u554a\uff0c\u8be6\u7ec6\u5230\u5e94\u8be5\u4ec0\u4e48\u7ed3\u679c\u5b9e\u9645\u4ec0\u4e48\u7ed3\u679c\uff0c\u751a\u81f3\u8fd8\u6709\u9519\u8bef\u4ee3\u7801\u4f4d\u7f6e\uff0c\u4e0d\u9519\u4e0d\u9519!<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/128.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u6069\uff0c\u786e\u5b9e\uff0c\u8bf4\u5b9e\u8bdd\uff0c\u6211\u5f00\u59cb\u6709\u70b9\u559c\u6b22QUnit\u4e86\u3002\u4e0a\u4f8b\u5b50\u6709demo\u7684\uff0c\u52ff\u6d6a\u8d39\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-3.html\" class=\"a_link\" target=\"_blank\">\u66f4\u5b8c\u6574\u591a\u5339\u914d\u6d4b\u8bd5\u4e0d\u901a\u8fc7demo<\/a><\/p>\n<p style=\"text-indent:27px;\">\u53d1\u73b0\u81ed\u866b\uff0c\u4e8b\u60c5\u5c31\u597d\u529e\u591a\u4e86\uff0c\u591a\u5339\u914d\u51fa\u9519\uff0c\u5f88\u5feb\u5c31\u4f1a\u53d1\u73b0\u539f\u6765\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u90a3\u91cc\uff0c\u5168\u5c40\u5339\u914d\u7684<code>\"g\"<\/code>\u7ed9\u5f04\u4e22\u4e86\uff0c\u62ff\u8d77\u654c\u654c\u754f\u55b7\u4e0a\u5c31\u5662\u5566\u3002<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\"><span class=\"js__operator\">new<\/span>&nbsp;<span class=\"js__object\">RegExp<\/span>(<span class=\"js__string\">\"\\{\"<\/span>&nbsp;+&nbsp;key&nbsp;+&nbsp;<span class=\"js__string\">\"}\"<\/span>,&nbsp;<span class=\"js__string\">\"g\"<\/span>)<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u4e8e\u662f\u4e4e\uff0c\u4e24\u4e2a\u6d4b\u8bd5\u90fd\u53ef\u4ee5\u901a\u8fc7\u5566\u3002\u5982\u679c\u662f\u5b9e\u9645\u9879\u76ee\uff0c\u663e\u7136\uff0c\u8fd9\u4e2a\u6d4b\u8bd5\u6709\u5fc5\u8981\u505a\u8fdb\u4e00\u6b65\u7684\u6269\u5c55\uff0c\u5339\u914d\u7684\u5bf9\u8c61\u4e0d\u6b62\u4e00\u4e2a\u5173\u952e\u5b57\u4ee5\u53ca\u5bf9\u8c61\u5173\u952e\u5b57\u8981\u7f3a\u5931\uff08\u662f\u5426\u663e\u793a<code>undefined<\/code>\uff09\u7b49\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8981\u8bb2\u8bb2\u5982\u4f55\u907f\u514d\u4e00\u4e2a\u6d4b\u8bd5\u641e\u8ddb\u53e6\u5916\u7684\u6d4b\u8bd5\u3002coffee time~ <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/60.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\">  <img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/yixiu.png\" alt=\"\u4e00\u4f11\u54e5\" align=\"absmiddle\"><\/p>\n<h3>\u56db\u3001\u9897\u7c92\u3001\u5355\u5143<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u5982\u679c\u4ec5\u4ec5\u662f\u6beb\u65e0\u526f\u4f5c\u7528\u7684\u529f\u80fd\u6d4b\u8bd5\uff0c\u90a3\u5b9e\u9645\u4e0a\u5f88\u8f7b\u677e\u7684\u3002\u4f46\u662f\uff0c\u4e00\u65e6\u4ee3\u7801\u5177\u6709\u526f\u4f5c\u7528\uff0c\u4f8b\u5982\u4fee\u6539DOM\u6216\u8005\u6539\u53d8\u5168\u5c40\u53d8\u91cf\uff0c\u4e8b\u4ef6\u5c31\u53d8\u5f97\u68d8\u624b\u4e86\u3002\u56e0\u6b64\uff0c\u6709\u5fc5\u8981\u8ba9\u6d4b\u8bd5\u9897\u7c92\u76f8\u4e92\u72ec\u7acb\uff0c\u964d\u4f4e\u53ef\u80fd\u7684\u526f\u4f5c\u7528\u3002QUnit\u63d0\u4f9b\u7684\u4e00\u4e9b\u5de5\u5177\u4ee5\u4fbf\u4f7f\u7528\u3002<\/p>\n<p style=\"text-indent:27px;\"><strong>\u7279\u5b9a\u7684DOM<\/strong><\/p>\n<p style=\"text-indent:27px; padding-top:0;\">\u5982\u679c\u8981\u6d4b\u8bd5DOM\u4fee\u6539\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>#qunit-fixture<\/code>\u5143\u7d20\u3002<code>#qunit-fixture<\/code>\u5143\u7d20\u597d\u6bd4\u6e38\u620f\u4e2d\u7684\u5c0f\u602a\uff0c\u4f60\u53ef\u4ee5\u968f\u4fbf\u780d\u6740\u589e\u957f\u7ecf\u9a8c\uff0c\u800c\u4e0d\u8981\u62c5\u5fc3\u7b2c\u4e8c\u5929\u4e0a\u673a\u7684\u65f6\u5019\u5c0f\u602a\u90fd\u6ca1\u4e86\u3002\u5728\u505a\u6d4b\u8bd5\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u9759\u6001\u6807\u8bb0\u4f60\u53ef\u4ee5\u968f\u4fbf\u7f6e\u7a7a\u6216<code>append<\/code>\u5143\u7d20\uff0c\u6bcf\u4e2a\u6d4b\u8bd5\u7ed3\u675f\u7684\u65f6\u5019QUnit\u4f1a\u81ea\u52a8\u628a<code>#qunit-fixture<\/code>\u5143\u7d20\u7684<code>innerHTML<\/code>\u5c5e\u6027\u503c\u8bbe\u7f6e\u4e3a\u521d\u59cb\u503c\u3002\u5982\u679c\u53ef\u4ee5\u4f7f\u7528jQuery\uff0cQUnit\u4f1a\u4f7f\u7528jQuery\u7684<code>html()<\/code>\u65b9\u6cd5\u4ee3\u66ff\uff0c\u540c\u65f6\u6e05\u9664jQuery\u4e8b\u4ef6\u53e5\u67c4\u3002<\/p>\n<p style=\"text-indent:27px;\">\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u60f3\u6d4b\u8bd5HTML5 <code>placeholder<\/code>\u7684\u586b\u5145\u6027\uff0c\u6211\u4eec\u4f1a\u6709\u4e00\u4e2a<code>input<\/code>\u5143\u7d20\u5e76\u5e26\u6709<code>placeholder<\/code>\u5c5e\u6027\uff1a<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\"><span class=\"html__tag_start\">&lt;div<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"qunit-fixture\"<\/span><span class=\"html__tag_start\">&gt;<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"html__tag_start\">&lt;input<\/span>&nbsp;<span class=\"html__attr_name\">id<\/span>=<span class=\"html__attr_value\">\"input\"<\/span>&nbsp;<span class=\"html__attr_name\">type<\/span>=<span class=\"html__attr_value\">\"text\"<\/span>&nbsp;<span class=\"html__attr_name\">placeholder<\/span>=<span class=\"html__attr_value\">\"placeholder&nbsp;text\"<\/span>&nbsp;<span class=\"html__tag_start\">\/&gt;<\/span><\/li><li style=\"\"><span class=\"html__tag_end\">&lt;\/div&gt;<\/span><\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u73b0\u5728\uff0c\u6bcf\u4e2a\u6d4b\u8bd5\u4f60\u90fd\u53ef\u4ee5\u9009\u62e9<code>#input<\/code>\u5143\u7d20\uff0c\u6253\u4ed6\uff0c\u9a82\u4ed6\uff0cQUnit\u4e4b\u540e\u90fd\u4f1a\u8ba9\u5b83\u6ee1\u8840\u590d\u6d3b\u7684\u3002<\/p>\n<p style=\"text-indent:27px;\"><strong>module &#8211; \u6a21\u5757<\/strong><\/p>\n<p style=\"text-indent:27px; padding-top:0;\">\u5982\u679c\u6211\u4eec\u9700\u8981\u66f4\u591a\u6e05\u9664\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f\u91cd\u65b0\u8bbe\u7f6eDOM\uff0c\u6211\u4eec\u53ef\u4ee5\u4f5c\u4e3a\u6bcf\u4e2a\u6d4b\u8bd5\u7684\u4e00\u90e8\u5206\u5b9e\u73b0\u3002\u5982\u679c\u5728\u591a\u4e2a\u6d4b\u8bd5\u4e2d\uff0c\u6211\u4eec\u6700\u7ec8\u505a\u7684\u662f\u540c\u4e00\u4e2a\u6e05\u9664\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>module()<\/code>\u65b9\u6cd5\u91cd\u6784\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u4e0d\u592a\u61c2~~ <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/32.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u4e0a\u9762\u662f\u5b57\u9762\u7ffb\u8bd1\u3002\u901a\u4fd7\u8bb2\u5c31\u662f\uff1a\u5982\u679c\u4f60\u6709\u5f88\u591a\u7684\u63a8\u5012\u3001\u7206\u83ca\u4e4b\u7c7b\uff0c\u4f60\u53ef\u4ee5\u6bcf\u6b21\u6d4b\u8bd5\u641e\u4e00\u4e0b\u3002\u5982\u679c\u8981\u641e\u5f88\u591a\u6b21\uff0c\u6bcf\u6b21\u90fd\u662f\u7206\u83ca\uff0c\u5219\u4f60\u53ef\u4ee5\u4f7f\u7528<code>module()<\/code>\u65b9\u6cd5\u91cd\u6784\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u4eae\u4e86\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/51.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> <code>module()<\/code>\u65b9\u6cd5\u521d\u8877\u662f\u5206\u7ec4\u6d4b\u8bd5\uff0c\u4f8b\u5982\uff0c\u591a\u4e2a\u6d4b\u8bd5\u90fd\u6d4b\u8bd5\u4e00\u4e2a\u7279\u6b8a\u7684\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u5c31\u53ef\u4ee5\u4f5c\u4e3a\u5355\u4e2a\u6a21\u5757\u7684\u4e00\u90e8\u5206\u3002\u8fd9\u6709\u52a9\u4e8e\u8fc7\u6ee4\u6d4b\u8bd5\uff08\u89c1\u4e0b\u9762\u201cQUnit\u4e0b\u7684\u5f00\u53d1\u201d\uff09\u3002\u4e3a\u4e86\u8ba9\u6d4b\u8bd5\u66f4\u52a0\u9897\u7c92\u5316\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>module()<\/code>\u63d0\u4f9b\u7684<code>setup<\/code>\u548c<code>teardown<\/code>\u56de\u8c03\u3002<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">module(<span class=\"js__string\">\"core\"<\/span>,&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;setup:&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__sl_comment\">\/\/&nbsp;\u5728\u6bcf\u4e2a\u6d4b\u8bd5\u4e4b\u524d\u8fd0\u884c<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>,<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;teardown:&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__sl_comment\">\/\/&nbsp;\u5728\u6bcf\u4e2a\u6d4b\u8bd5\u4e4b\u540e\u8fd0\u884c<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span><\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">test(<span class=\"js__string\">\"basics\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__sl_comment\">\/\/&nbsp;\u6d4b\u8bd5\u2026\u2026<\/span><\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\"><code>setup<\/code>\u56de\u8c03\u90fd\u662f\u5728\u6d4b\u8bd5\u4e4b\u524d\u8fd0\u884c\uff0c<code>teardown<\/code>\u56de\u8c03\u662f\u5728\u6d4b\u8bd5\u4e4b\u540e\u8fd0\u884c\u3002<\/p>\n<p style=\"text-indent:27px;\">\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u56de\u8c03\u521b\u5efa\u5bf9\u8c61\u5e76\u5728\u6d4b\u8bd5\u4e2d\u4f7f\u7528\uff0c\u800c\u65e0\u9700\u4f9d\u9760\u95ed\u5305\uff08\u6216\u5168\u5c40\u53d8\u91cf\uff09\u4f20\u7ed9\u6d4b\u8bd5\u3002\u4e4b\u6240\u4ee5\u4f1a\u8d77\u4f5c\u7528\uff0c\u662f\u56e0\u4e3a<code>setup<\/code>\u548c<code>teardown<\/code>\u4ee5\u53ca\u771f\u5b9e\u7684\u6d4b\u8bd5\u90fd\u5728\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u53ef\u4ee5\u81ea\u52a8\u5171\u4eab\u548c\u6e05\u9664\u7684\u4f5c\u7528\u57df\u4e2d\u8c03\u7528\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u4f3c\u61c2\u975e\u61c2\uff0c\u4e3e\u4e2a\u4f8b\u5b50\u5457\u3002<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/29.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u6b63\u6709\u6b64\u610f\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u662f\u4e2a\u7b80\u5355\uff08\u4f46\u4e0d\u5b8c\u6574\uff09\u7684\u5e93\uff0c\u7528\u6765\u5904\u7406\u8d27\u5e01\u503c\u3002<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\"><span class=\"js__statement\">var<\/span>&nbsp;Money&nbsp;=&nbsp;<span class=\"js__operator\">function<\/span>(options)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">this<\/span>.amount&nbsp;=&nbsp;options.amount&nbsp;||&nbsp;<span class=\"js__num\">0<\/span>;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">this<\/span>.template&nbsp;=&nbsp;options.template&nbsp;||&nbsp;<span class=\"js__string\">\"{symbol}{amount}\"<\/span>;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">this<\/span>.symbol&nbsp;=&nbsp;options.symbol&nbsp;||&nbsp;<span class=\"js__string\">\"$\"<\/span>;<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>;<\/li><li style=\"\">Money.prototype&nbsp;=&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;add:&nbsp;<span class=\"js__operator\">function<\/span>(toAdd)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">this<\/span>.amount&nbsp;+=&nbsp;toAdd;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>,<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;toString:&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">return<\/span>&nbsp;<span class=\"js__operator\">this<\/span>.template<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.replace(<span class=\"js__string\">\"{symbol}\"<\/span>,&nbsp;<span class=\"js__operator\">this<\/span>.symbol)<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.replace(<span class=\"js__string\">\"{amount}\"<\/span>,&nbsp;<span class=\"js__operator\">this<\/span>.amount)<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span><\/li><li style=\"\"><span class=\"js__brace\">}<\/span>;<\/li><li style=\"\">Money.euro&nbsp;=&nbsp;<span class=\"js__operator\">function<\/span>(amount)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">return<\/span>&nbsp;<span class=\"js__operator\">new<\/span>&nbsp;Money(<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount:&nbsp;amount,<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;template:&nbsp;<span class=\"js__string\">\"{amount}&nbsp;{symbol}\"<\/span>,<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;symbol:&nbsp;<span class=\"js__string\">\"EUR\"<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>;<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u4e0a\u9762\u4ee3\u7801\u521b\u5efa\u4e86\u4e2a<code>Money<\/code>\u5bf9\u8c61\uff0c\u6709\u4e2a\u4e3a\u7f8e\u5143(dollars)\u521b\u5efa\u7684\u4e2a\u9ed8\u8ba4\u6784\u9020\u5668\u65b9\u6cd5\uff0c\u8fd8\u6709\u4e00\u4e2a\u4e3a\u6b27\u5143(euro)\u521b\u5efa\u7684\u5de5\u5382\u65b9\u6cd5\u3002\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u4f5c\u7528\u90fd\u662f\u64cd\u63a7\u548c\u6253\u5370\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u4e0d\u662f\u4e3a\u6bcf\u4e2a\u6d4b\u8bd5\u90fd\u521b\u5efa\u4e00\u4e2a\u65b0\u7684<code>Money<\/code>\u5bf9\u8c61\uff0c\u800c\u662f\u4f7f\u7528<code>setup<\/code>\u56de\u8c03\u521b\u5efa\u5bf9\u8c61\u5e76\u5b58\u50a8\u5728\u6d4b\u8bd5\u4f5c\u7528\u57df\u4e2d\u3002<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">module(<span class=\"js__string\">\"Money\"<\/span>,&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;setup:&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">this<\/span>.dollar&nbsp;=&nbsp;<span class=\"js__operator\">new<\/span>&nbsp;Money(<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount:&nbsp;<span class=\"js__num\">15.5<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">this<\/span>.euro&nbsp;=&nbsp;Money.euro(<span class=\"js__num\">14.5<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>,<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;teardown:&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__sl_comment\">\/\/&nbsp;\u53ef\u4ee5\u4f7f\u7528this.dollar\u548cthis.euro\u4f5c\u6e05\u9664<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span><\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;<\/li><li style=\"\">test(<span class=\"js__string\">\"add\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;equal(&nbsp;<span class=\"js__operator\">this<\/span>.dollar.amount,&nbsp;<span class=\"js__num\">15.5<\/span>&nbsp;);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">this<\/span>.dollar.add(<span class=\"js__num\">16.1<\/span>)<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;equal(&nbsp;<span class=\"js__operator\">this<\/span>.dollar.amount,&nbsp;<span class=\"js__num\">31.6<\/span>&nbsp;);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">test(<span class=\"js__string\">\"toString\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;equal(&nbsp;<span class=\"js__operator\">this<\/span>.dollar.toString(),&nbsp;<span class=\"js__string\">\"$15.5\"<\/span>&nbsp;);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;equal(&nbsp;<span class=\"js__operator\">this<\/span>.euro.toString(),&nbsp;<span class=\"js__string\">\"14.5&nbsp;EUR\"<\/span>&nbsp;);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u4e0a\u4ee3\u7801\u4e2d\uff0c<code>setup<\/code>\u56de\u8c03\u4e2d\u521b\u5efa\u4e86\u4e24\u4e2a\u5bf9\u8c61\uff0c\u540d\u53eb<code>\"add\"<\/code>\u7684\u6d4b\u8bd5\u4e4b\u4f7f\u7528\u4e86\u4e00\u4e2a\uff0c<code>\"toString\"<\/code>\u8fd9\u4e2a\u6d4b\u8bd5\u4e24\u4e2a\u5bf9\u8c61\u90fd\u4f7f\u7528\u4e86\u3002\u672c\u4f8b\u4e2d\uff0c<code>teardown<\/code>\u56de\u8c03\u6ca1\u5fc5\u8981\u4f7f\u7528\uff0c\u56e0\u4e3a\u6ca1\u5fc5\u8981\u8981\u79fb\u9664\u5df2\u7ecf\u521b\u5efa\u7684<code>Money<\/code>\u5bf9\u8c61\u3002\u7ed3\u679c\u5982\u4e0b\u622a\u56fe\uff1a<\/p>\n<p style=\"text-indent:27px;padding-top:0;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_155945.png\" alt=\"module\u4f7f\u7528\u6d4b\u8bd5\u7ed3\u679c\u622a\u56fe\" height=\"227\"><\/p>\n<p style=\"text-indent:27px;\">\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-4.html\" class=\"a_link\" target=\"_blank\">module\u4e0e\u5355\u5143\u6d4b\u8bd5demo<\/a><\/p>\n<h3>\u4e94\u3001\u6d4b\u8bd5\u5f02\u6b65\u4ee3\u7801<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u6211\u4eec\u5df2\u7ecf\u770b\u4ee5\uff0cQUnit\u53ef\u4ee5\u63a7\u5236\u4ec0\u4e48\u65f6\u5019\u771f\u6b63\u8fd0\u884c\u6d4b\u8bd5\u4ee3\u7801\uff0c\u53ea\u8981\u4ee3\u7801\u662f\u540c\u6b65\u8fd0\u884c\u7684\u3002\u7136\u800c\uff0c\u4e00\u65e6\u6d4b\u8bd5\u7684\u4ee3\u7801\u9700\u8981\u4f7f\u7528\u5f02\u6b65\u56de\u8c03\uff08\u5982<code>setTimeout<\/code>\u6216Ajax\u8bf7\u6c42\uff09\uff0c\u4f60\u9700\u8981\u7ed9QUnit\u53cd\u9988\uff0c\u4ee5\u4fbf\u505c\u6b62\u540e\u9762\u7684\u6d4b\u8bd5\uff0c\u77e5\u9053\u4f60\u8ba9\u5b83\u518d\u6b21\u8fd0\u884c\u3002<\/p>\n<p style=\"text-indent:27px;\">\u4f7f\u7528\u7684\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u5c31\u662f<code>start()<\/code>\u548c<code>end()<\/code>\uff0c\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">test(<span class=\"js__string\">\"async\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;stop();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;$.getJSON(<span class=\"js__string\">\"resource\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>(result)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deepEqual(result,&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status:&nbsp;<span class=\"js__string\">\"ok\"<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u8fd9\u91ccjQuery\u7684<code>$.getJSON<\/code>\u65b9\u6cd5\u88ab\u7528\u6765\u4ece<code>\"resource\"<\/code>\u4e2d\u8bf7\u6c42\u6570\u636e\uff0c\u7136\u540e\u5224\u65ad\u7ed3\u679c\u3002<code>deepEqual<\/code>\uff08\u6709\u522b\u4e8e\u5f00\u59cb\u7684<code>equal<\/code>\uff09\u7528\u6765\u68c0\u6d4b\u7ed3\u679c\u662f\u5426\u5b8c\u5168\u662f\u6211\u4eec\u6240\u671f\u671b\u7684\uff08\u6bd4\u65b9\u8bf4<code>var a={}, b ={};<\/code> <code>\/\/<\/code> <code>a==b \u2192 false<\/code>\uff0c\u4f46\u662f\uff0c\u4f7f\u7528<code>deepEqual<\/code>\uff0c<code>a==b<\/code>\u4e3a<code>true<\/code>\uff09\u3002<\/p>\n<p style=\"text-indent:27px;\">\u56e0\u4e3a<code>$.getJSON<\/code>\u662f\u5f02\u6b65\u7684\uff0c\u6211\u4eec\u8c03\u7528<code>stop()<\/code>, \u7136\u540e\u8fd0\u884c\u4ee3\u7801\uff0c\u518d\u5728<code>callback<\/code>\u7ed3\u675f\u7684\u65f6\u5019\u8c03\u7528<code>start()<\/code>, \u544a\u8bc9QUnit\u7ee7\u7eed\u8fd0\u884c\u3002<\/p>\n<p style=\"text-indent:27px;\">\u8fd0\u884c\u5f02\u6b65\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u5982\u679c\u6ca1\u6709\u4f7f\u7528<code>stop()<\/code>\uff0c\u4f1a\u5bfc\u81f4\u672c\u610f\u662f\u5176\u4ed6\u6d4b\u8bd5\u7684\u4efb\u610f\u7ed3\u679c\uff0c\u5982<code>passed<\/code>\u6216<code>failed<\/code>.<\/p>\n<p style=\"text-indent:27px;\"><strong>asyncTest<\/strong><\/p>\n<p style=\"text-indent:27px;\">\u5982\u679c\u6211\u4eec\u4f7f\u7528<code>asyncTest()<\/code>\u4ee3\u66ff<code>test()<\/code>, \u6211\u4eec\u5c31\u53ef\u4ee5\u628a<code>stop()<\/code>\u7701\u6389\u3002\u4e8e\u662f\uff0c\u6211\u4eec\u4e00\u773c\u5c31\u53ef\u4ee5\u770b\u51fa\u8fd9\u662f\u4e2a\u5f02\u6b65\u6d4b\u8bd5\u3002<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">asyncTest(<span class=\"js__string\">\"async2\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;$.getJSON(<span class=\"js__string\">\"resource\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>(result)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deepEqual(result,&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status:&nbsp;<span class=\"js__string\">\"ok\"<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/29.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u7ee7\u7eed\uff0c\u8fd8\u6709\u5176\u4ed6\u7684API\u65b9\u6cd5\u3002<\/p>\n<p style=\"text-indent:27px;\"><strong>expect<\/strong><\/p>\n<p style=\"text-indent:27px;padding-top:0;\">\u6d4b\u8bd5\u56de\u8c03\u7684\u65f6\u5019\uff0c\u65e0\u8bba\u662f\u4e0d\u662f\u5f02\u6b65\uff0c\u6211\u4eec\u90fd\u4e0d\u80fd\u786e\u5b9a\u56de\u8c03\u4f1a\u5728\u67d0\u4e9b\u65f6\u5019\u88ab\u771f\u6b63\u8c03\u7528\u4e86\u3002\u4e3a\u4e86\u5e94\u4ed8\u8fd9\u79cd\u72b6\u51b5\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>expect()<\/code>, \u5b9a\u4e49\u4e00\u4e2a\u6d4b\u8bd5\u4e2d\u6211\u4eec\u671f\u671b\u7684\u5224\u65ad\u4e2a\u6570\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u907f\u514d\u672c\u5e94\u51fa\u73b0\u4e24\u4e2a\u5224\u522b\u7ed3\u679c\u7684\uff0c\u7ed3\u679c\u4e00\u4e2a\u901a\u8fc7\u540e\u5c31\u505c\u6b62\u7684\u60c5\u51b5\u3002<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">asyncTest(<span class=\"js__string\">\"async3\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;expect(<span class=\"js__num\">1<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;$.getJSON(<span class=\"js__string\">\"resource\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>(result)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deepEqual(result,&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status:&nbsp;<span class=\"js__string\">\"ok\"<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u8fd9\u91cc\uff0c<code>asyncTest()<\/code>\u4e2d\uff0c<code>expect<\/code>\u88ab\u8c03\u7528\uff0c\u53c2\u6570\u4e3a<code>1<\/code>, \u76f8\u5bf9\u4e8e\u544a\u8bc9QUnit\u8fd9\u91cc\u7684\u6d4b\u8bd5\u5e94\u8be5\u53ea\u6709\u4e00\u6b21\u5224\u5b9a\u3002\u8fd9\u6709\u4ec0\u4e48\u597d\u5904\u5462\uff1f\u5f53\u6211\u4eec\u540c\u65f6\u505a\u591a\u4e2a\u5f02\u6b65\u6d4b\u8bd5\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u5176\u4ed6\u7684\u6d4b\u8bd5\u55dd\u5c41\u88ab\u7834\u574f\uff0c\u7136\u540e\u4e5f\u5f04\u51fa\u4e86\u4e00\u4e2a\u5224\u5b9a\uff0c\u6b64\u65f6<code>expect<\/code>\u5c31\u53ef\u4ee5\u6355\u83b7\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p style=\"text-indent:27px;\"><code>expect()<\/code>\u8c8c\u4f3c\u6709\u4e2a\u53d6\u5de7\u7684\u8bbe\u7f6e\u65b9\u6cd5\uff0c\u5c31\u662f\u7ed9<code>test()<\/code>\u6216<code>asyncTest()<\/code>\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u9012\u4e00\u4e2a\u6570\u5b57\uff0c\u4f8b\u5982\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u5199\u6210\uff1a<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">asyncTest(<span class=\"js__string\">\"async4\"<\/span>,&nbsp;<span class=\"js__num\">1<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;$.getJSON(<span class=\"js__string\">\"resource\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>(result)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deepEqual(result,&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status:&nbsp;<span class=\"js__string\">\"ok\"<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u662f\u4e0d\u662f\u5e94\u8be5\u653edemo\u5566\u3002<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/29.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u7a0d\u5b89\u52ff\u8e81\uff0c\u8fd8\u6709\u4e00\u90e8\u5206\uff0c\u4ecb\u7ecd\u5b8c\u4e86\u4e00\u8d77\u653e\u51fa\u6765\u3002<\/p>\n<p style=\"text-indent:27px;\"><strong>\u5f02\u6b65\u4fe1\u53f7<\/strong><\/p>\n<p style=\"text-indent:27px;\">\u5982\u679c\u6d4b\u8bd5\u7684\u7ed3\u675f\u70b9\u591a\u4e2a-\u591a\u4e2a\u56de\u8c03\u7684\u987a\u5e8f\u968f\u673a-\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528QUnit\u5185\u7f6e\u4fe1\u53f7\u3002\u8c03\u7528<code>stop()<\/code>\u4e0e\u4e4b\u540e\u8c03\u7528\u7684<code>start()<\/code>\u540c\u6570\u76ee\uff0c\u5219Qunit\u4f1a\u7ee7\u7eed\u8fd0\u884c\u76f4\u5230<code>stop()<\/code>\u589e\u52a0\u7684\u8ba1\u6570\u88ab<code>start()<\/code>\u51cf\u5c11\u4f1a<code>0<\/code>.<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">test(<span class=\"js__string\">\"async&nbsp;semaphore\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;stop();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;stop();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;$.getJSON(<span class=\"js__string\">\"resource\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>(result)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;equal(result.status,&nbsp;<span class=\"js__string\">\"ok\"<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;$.getJSON(<span class=\"js__string\">\"resource\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>(result)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;equal(result.status,&nbsp;<span class=\"js__string\">\"ok\"<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u8bf4\u597d\u7684demo\u5462\uff1f<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/29.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u771f**\u7334\u6025\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-5.html\" class=\"a_link\" target=\"_blank\">\u4e0a\u9762\u6240\u6709\u5f02\u6b65\u6d4b\u8bd5\u96c6\u5408demo<\/a> \u6e90\u4ee3\u7801\u53f3\u952e\u53ef\u67e5\u770b\u3002<\/p>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_173540.png\" alt=\"\u5f02\u6b65\u6d4b\u8bd5\u7ed3\u679c\u622a\u56fe \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" height=\"272\"><\/p>\n<h3>\u516d\u3001\u66f4\u591a\u7684\u6d4b\u8bd5\u5224\u65ad<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> <code>equal<\/code>\u548c<code>deepEqual<\/code>\u5df2\u7ecf\u5728\u524d\u9762\u767b\u53f0\u4eae\u76f8\u4e86\u3002\u5b9e\u9645\u4e0a\uff0cQUnit\u63d0\u4f9b\u4e86\u8fdc\u4e0d\u6b62\u8fd9\u51e0\u4e2a\u5224\u65ad\uff0c\u6bd4\u65b9\u8bf4<code>strict<\/code>, \u4f7f\u7528\u548c<code>eauql<\/code>\u4e00\u6837\uff0c\u9664\u4e86\u4f7f\u7528\u7684\u662fJavaScript\u4e2d\u7684<code>\"===\"<\/code>\u4e25\u683c\u5bf9\u6bd4\u64cd\u4f5c\u7b26\u3002\u5f53\u5bf9\u6bd4\u4e0d\u540c\u7c7b\u578b\u503c\u7684\u65f6\u5019\uff0c\u4f8b\u5982\u6570\u503c\u548c\u5b57\u7b26\u4e32\u6bd4\u8f83\uff0c<code>eauql<\/code>\u5c31\u6709\u7528\u6b66\u4e4b\u5730\u4e86\uff0c\u8fd9\u6837\u4f60\u7684\u6d4b\u8bd5\u5c31\u4e0d\u4f1a\u6b7b\u5728<code>0<\/code>\u7b49\u4e8e<code>\"0\"\u4e0a<\/code>\u3002<\/p>\n<p style=\"text-indent:27px;\">\u6709\u6b63\u5fc5\u6709\u90aa\uff0c\u56e0\u6b64\uff0c\u8ddf<code>equal<\/code>, <code>deepEqual<\/code>\u548c<code>strictEqual<\/code>\u76f8\u53cd\uff0c\u8fd9\u91cc\u8fd8\u6709<code>notEqual<\/code>, <code>notDeepEqual<\/code>, <code>notStrictEqual<\/code>. \u540c\u6837\u7684\u89c4\u5219\uff0c\u4e0d\u4e00\u6837\u7684\u7ed3\u679c\u3002<\/p>\n<p style=\"text-indent:27px;\"><strong>raises<\/strong><\/p>\n<p style=\"text-indent:27px;padding-top:0;\">\u9664\u4e86\u8fd9\u4e9b\uff0c\u8fd8\u6709<code>raises<\/code>(\u7c7b\u4f3cCommonJS\u4e2d\u7684<code>throws<\/code>\uff0c\u4e0d\u8fc7\u6ca1\u6709\u4f7f\u7528\u4fdd\u7559\u5173\u952e\u5b57). \u4f60\u4f20\u9012\u4e00\u4e2a<code>function<\/code>\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u5176\u4f1a\u88abQUnit\u4e2d\u7684<code>try-catch<\/code>\u8bed\u53e5\u4e2d\u8c03\u7528\u3002\u5982\u679c\u8fd9\u4e2a\u51fd\u6570\u629b\u51fa\u5f02\u5e38\uff0c\u5219\u6211\u4eec\u8ba4\u4e3a\u901a\u8fc7-<code>pass<\/code>\uff0c\u5426\u5219\u4e0d\u901a\u8fc7-<code>fail<\/code>\u3002\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e8c\u4e2a\u53c2\u6570\u68c0\u6d4b\u629b\u51fa\u7684\u5f02\u5e38\u3002\u53ef\u4ee5\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6216\u8005\u662f\u6784\u9020\u51fd\u6570\uff08\u4f7f\u629b\u51fa\u9519\u8bef\u4f1a<code>instanceof<\/code>\u8fd9\u4e2a\u6784\u9020\u51fd\u6570\uff09\u68c0\u6d4b\uff0c\u6216\u8005\u662f\u4e00\u4e2a\u8fd4\u56de<code>true<\/code>\u6216<code>false<\/code>\u7684\u51fd\u6570\uff08\u6b64\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5c31\u662f\u629b\u51fa\u7684\u5f02\u5e38\uff09\u3002<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">test(<span class=\"js__string\">\"raises\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">function<\/span>&nbsp;CustomError()&nbsp;<span class=\"js__brace\">{<\/span><span class=\"js__brace\">}<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;raises(<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">throw<\/span>&nbsp;<span class=\"js__operator\">new<\/span>&nbsp;CustomError();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>,&nbsp;CustomError,&nbsp;<span class=\"js__string\">\"must&nbsp;throw&nbsp;error&nbsp;to&nbsp;pass\"<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>);<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u4e0a\u9762\u793a\u4f8b\u663e\u793a\u4e86<code>raises<\/code>\u5982\u4f55\u901a\u8fc7\u4f20\u9012\u9884\u671f\u7684\u6784\u9020\u51fd\u6570\u5f15\u7528\u4f5c\u4e3a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6765\u68c0\u6d4b\u6784\u9020\u51fd\u6570\u629b\u51fa\u7684\u5f02\u5e38\u3002\u7ed3\u679c\u5982\u4e0b\u56fe\uff0c\u901a\u8fc7\uff1a<\/p>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_183723.png\" alt=\"\u5f02\u5e38\u68c0\u6d4b\u7ed3\u679c \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\"><\/p>\n<p>\u4e4b\u6240\u4ee5\u4f1a\u6709\u4e0a\u9762\u7684\u7ed3\u679c\uff0c\u662f\u56e0\u4e3a\u629b\u51fa\u7684\u9519\u8bef <code>instanceof<\/code> <code>CustomError<\/code>\u4e3a<code>true<\/code>. \u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-6.html\" class=\"a_link\" target=\"_blank\">\u629b\u51fa\u5f02\u5e38\u68c0\u6d4bdemo<\/a><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/29.gif\" align=\"absmiddle\"><\/p>\n<h3>\u4e03\u3001\u81ea\u5b9a\u4e49\u5224\u65ad<\/h3>\n<p>\u5c31\u662f\u8ba9\u6211\u4eec\u76f4\u63a5\u4f7f\u7528<code>QUnit.push()<\/code>\u8fdb\u884c\u5c01\u88c5\u81ea\u5b9a\u4e49\u4e00\u4e9b\u5224\u65ad\u65b9\u6cd5, \u800c\u4e0d\u662f\u4e0a\u9762\u7684<code>equal<\/code>\u4e4b\u7c7b\u3002<code>QUnit.push()<\/code>\u4e0e<code>equal<\/code>\u7b49\u5173\u7cfb\uff0c\u5c31\u597d\u6bd4jQuery\u4e2d<code>$.ajax()<\/code>\u65b9\u6cd5\u548c<code>$.post()\/$.get()<\/code>\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u4e0b\u9762\u4f8b\u5b50\u5c31\u662f\u4f7f\u7528<code>QUnit.push()<\/code>\u81ea\u5b9a\u4e49\u7684\u4e00\u4e2a\u9a8c\u8bc1DOM\u7684\u67d0\u4e9b\u5c5e\u6027\u3001\u5305\u62ec\u5b50\u5143\u7d20\u524d\u540e\u662f\u5426\u53d1\u751f\u53d8\u5316\u7684\u65b9\u6cd5\u3002<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\"><span class=\"js__operator\">function<\/span>&nbsp;domEqual(&nbsp;selector,&nbsp;modifier,&nbsp;message&nbsp;)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">var<\/span>&nbsp;attributes&nbsp;=&nbsp;[<span class=\"js__string\">\"class\"<\/span>,&nbsp;<span class=\"js__string\">\"role\"<\/span>,&nbsp;<span class=\"js__string\">\"id\"<\/span>,&nbsp;<span class=\"js__string\">\"tabIndex\"<\/span>,&nbsp;<span class=\"js__string\">\"aria-activedescendant\"<\/span>];<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__operator\">function<\/span>&nbsp;extract(value)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">var<\/span>&nbsp;result&nbsp;=&nbsp;<span class=\"js__brace\">{<\/span><span class=\"js__brace\">}<\/span>;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result.nodeName&nbsp;=&nbsp;value[<span class=\"js__num\">0<\/span>].nodeName;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$.each(attributes,&nbsp;<span class=\"js__operator\">function<\/span>(index,&nbsp;attr)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[attr]&nbsp;=&nbsp;value.attr(attr);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result.children&nbsp;=&nbsp;[];<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">var<\/span>&nbsp;children&nbsp;=&nbsp;value.children();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">if<\/span>&nbsp;(children.length)&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;children.each(<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result.children.push(extract($(<span class=\"js__operator\">this<\/span>)));<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>&nbsp;<span class=\"js__statement\">else<\/span>&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result.text&nbsp;=&nbsp;value.text();<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">return<\/span>&nbsp;result;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">var<\/span>&nbsp;expected&nbsp;=&nbsp;extract($(selector));<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;modifier($(selector));<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__statement\">var<\/span>&nbsp;actual&nbsp;=&nbsp;extract($(selector));<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;QUnit.push(&nbsp;QUnit.equiv(actual,&nbsp;expected),&nbsp;actual,&nbsp;expected,&nbsp;message&nbsp;);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span><\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u4e0a\u9762\u4ee3\u7801\u867d\u7136\u86ee\u591a\uff0c\u5176\u5b9e\u8981\u505a\u7684\u4e8b\u60c5\u4e0d\u96be\u7406\u89e3\u3002\u68c0\u6d4b\u9009\u62e9\u5668<code>selector<\/code>\u5bf9\u5e94\u7684\u5143\u7d20<code>attributes<\/code>\u4e2d\u7684\u5c5e\u6027\u4ee5\u53ca\u5b50\u5143\u7d20\u662f\u5426\u5728<code>modifier()<\/code>\u8fd9\u4e2a\u65b9\u6cd5\u6267\u884c\u4e4b\u540e\u53d1\u751f\u4e86\u6539\u53d8\u3002\u4e0b\u9762\u5c31\u662f\u6d4b\u8bd5\u4ee3\u7801\uff08\u9700\u8981\u7528\u5230jQuery UI\uff09\uff1a<\/p>\n<div class=\"CodeHighlighter\">\n<pre><ol><li style=\"\">test(<span class=\"js__string\">\"destroy\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;domEqual(<span class=\"js__string\">\"#autocomplete\"<\/span>,&nbsp;<span class=\"js__operator\">function<\/span>()&nbsp;<span class=\"js__brace\">{<\/span><\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(<span class=\"js__string\">\"#autocomplete\"<\/span>).autocomplete().autocomplete(<span class=\"js__string\">\"destroy\"<\/span>);<\/li><li style=\"\">&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"js__brace\">}<\/span>);<\/li><li style=\"\"><span class=\"js__brace\">}<\/span>)<\/li><\/ol><\/pre>\n<\/div>\n<p style=\"text-indent:27px;\">\u5728\u9875\u9762\u4e0a\u653e\u4e86\u4e2aHTML\u4e3a<code>&lt;input id=\"autocomplete\"&gt;<\/code>\u7684\u4ee3\u7801\uff0c\u7ed3\u679c\u5982\u4e0b\u56fe\uff1a<\/p>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_192718.png\" alt=\"autocomplete\u4e0b\u81ea\u5b9a\u4e49domEqual\u65b9\u6cd5\u7684\u6d4b\u8bd5 \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" height=\"683\"><\/p>\n<p style=\"text-indent:27px;\">\u8c8c\u4f3c<code>modifier<\/code>\u6267\u884c\u540e\uff0cAutocomplete\u63d2\u4ef6\u5c06\u6587\u672c\u6846\u7684<code>className<\/code>\u6539\u6210\u4e86\u7a7a\u5b57\u7b26\u4e32\uff0c\u5bfc\u81f4\u6587\u672c\u6846\u524d\u540e\u53d8\u5316\u4e0d\u76f8\u7b49\u4e86\uff0c\u4e8e\u662f\u68c0\u6d4b\u7ed3\u679c\u4e3a<code>failed<\/code>\uff01\u5982\u679c\u9ed8\u8ba4HTML\u662f<code>&lt;input id=\"autocomplete\" class=\"\"&gt;<\/code>\uff0c\u5219\u7ed3\u679c\u662f<code>passed<\/code>\uff01\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-7.html\" class=\"a_link\" target=\"_blank\">autocomplete\u4e0b\u81ea\u5b9a\u4e49domEqual\u65b9\u6cd5\u68c0\u6d4bdemo<\/a><\/p>\n<h3>\u516b\u3001\u4f7f\u7528QUnit\u505a\u5f00\u53d1<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u6211\u52d2\u4e2a\u53bb\uff0c\u600e\u4e48\u8fd8\u6709\u8fd9\u4e48\u591a\u5185\u5bb9\uff0c\u6211\u8981\u5077\u5de5\u51cf\u6599\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> <img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/98.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u60a8\u53ef\u80fd\u6ce8\u610f\u5230\u7ed3\u679c\u8f93\u51fa\u9762\u677f\u4e0a\u6709\u4e2a\u4e0d\u592a\u660e\u663e\u7684<code>Rerun<\/code>\u6309\u94ae\uff0c\u610f\u601d\u662f\u201c\u91cd\u65b0\u8fd0\u884c\u201d\uff0c\u9875\u9762\u672c\u6765\u5c31\u53ef\u4ee5\u5237\u65b0\uff0c\u8fd8\u9700\u8981<code>Rerun<\/code>\u505a\u4ec0\u4e48\u5462\uff1f\u5728\u5b9e\u9645\u6d4b\u8bd5\u7684\u65f6\u5019\uff0c\u6d4b\u8bd5\u9762\u677f\u80af\u5b9a\u6709\u5f88\u591a\u7ed3\u679c\u7684\uff0c\u6709\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u5bf9\u67d0\u4e2a\u6d4b\u8bd5\u7ed3\u679c\u5f88\u5173\u5fc3\uff08\u6bd4\u65b9\u8bf4\u6d4b\u8bd5\u672a\u901a\u8fc7\uff09\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u70b9\u51fb<code>Rerun<\/code>\u6309\u94ae\uff0c\u4e8e\u662f\uff0c\u9875\u9762\u5c31\u53ea\u4f1a\u68c0\u6d4b\u8be5\u90e8\u5206\u7684\u4ee3\u7801\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u4e86\u3002\u4f8b\u5982\uff0c\u6211\u70b9\u51fb\u672c\u6587<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-5.html\">\u7b2c5\u4e2ademo<\/a>\u7684\u7b2c4\u4e2a<code>Rerun<\/code>\u6309\u94ae\uff0c\u5219\uff1a<\/p>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_201313.png\" alt=\"\u70b9\u51fbrerun\u6309\u94ae\" height=\"96\"><\/p>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_201447.png\" alt=\"\u70b9\u51fbrerun\u6309\u94ae\u540e\" height=\"224\"><\/p>\n<p style=\"text-indent:27px;\">\u901a\u8fc7\u683c\u5f0f\u5316\u7684<code>url<\/code>\u5730\u5740\u7b5b\u9009\u9700\u8981\u8fd0\u884c\u7684\u68c0\u6d4b\u4ee3\u7801\uff0c\u8fd9\u91cc\uff0c\u5c31\u6307\u68c0\u6d4b\u4e86\u7b2c4\u4e2a<code>Rerun<\/code>\u6309\u94ae\u5bf9\u5e94\u7684\u4ee3\u7801\u3002<\/p>\n<p style=\"text-indent:27px;\"><strong>\u8c03\u8bd5\u5de5\u5177<\/strong><\/p>\n<p style=\"text-indent:27px;\">\u5728<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-3.html\">\u7b2c3\u4e2ademo<\/a>\u4e2d\uff0c\u60a8\u53ef\u80fd\u6ce8\u610f\u5230\u4e86\u8fd9\u4e2a\uff1a<\/p>\n<p style=\"text-indent:27px;\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_202223.png\" alt=\"\u8c03\u8bd5\u5de5\u5177\" height=\"71\"><\/p>\n<p style=\"text-indent:27px;\">\u8fd9\u4e9b\u5c31\u662fQUnit\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u81f3\u4e8e\u5e72\u561b\u7528\u7684\uff0c\u5077\u5de5\u51cf\u6599\uff0c\u4e0d\u89e3\u91ca\uff0c(*^__^*) \u563b\u563b\u2026\u2026<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u4f19\u8ba1\uff0c\u8fd9\u53ef\u662f\u7164\u6cb9\u706f\uff0c\u4e0d\u80fd\u7701\u7684\uff0c\u518d\u8f9b\u82e6\u4e0b\u5457~~<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/98.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u597d\u5427\uff0c\u5185\u5fc3\u7684\u53e6\u4e00\u4e2a\u6211\u5728\u53ec\u5524\uff0c\u52a0\u6cb9\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/30.gif\" align=\"absmiddle\"><\/p>\n<ul>\n<li><strong>Hide passed tests<\/strong><br \/> \u201c\u9690\u85cf\u901a\u8fc7\u7684\u6d4b\u8bd5\u201d\uff0c\u5f88\u597d\u7406\u89e3\uff0c\u52fe\u9009\u540e\uff0c\u901a\u8fc7\u7684\u6d4b\u8bd5\u5c31\u4e0d\u663e\u793a\u4e86\uff0c\u5982\u4e0b<a href=\"http:\/\/www.zhangxinxu.com\/study\/201304\/qunit-test-3.html\">\u7b2c3demo<\/a>\u622a\u56fe\uff1a<br \/><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/2013-04-09_203236.png\" alt=\"\u9690\u85cf\u901a\u8fc7\u7684\u6d4b\u8bd5\u622a\u56fe\" height=\"310\"><\/li>\n<li><strong>Check for Globals<\/strong><br \/> \u201c\u5168\u5c40\u68c0\u6d4b\u201d\uff0c\u5982\u679c\u52fe\u9009\u6b64\u9879\uff0c\u5728\u8fd0\u884c\u6d4b\u8bd5\u4e4b\u524d\uff0cQUnit\u4f1a\u679a\u4e3e<code>window<\/code>\u6240\u6709\u5c5e\u6027\uff0c\u7136\u540e\u4e0e\u8fd0\u884c\u7ed3\u675f\u4e4b\u540e\u7684<code>window<\/code>\u505a\u6bd4\u8f83\uff0c\u5982\u679c\u524d\u540e\u4e0d\u4e00\u6837\uff0c\u54e6\u5475\u5475\uff0c\u5c31\u4f1a\u663e\u793a\u4e0d\u901a\u8fc7-<code>failed<\/code>, \u4ee5\u53ca\u663e\u793a\u201c\u5f15\u5165\u6216\u7f3a\u5931\u5168\u5c40\u5c5e\u6027\u201d\u3002\u8be5\u5de5\u5177\u4f5c\u7528\u5728\u4e8e\u53ef\u4ee5\u5f88\u5bb9\u6613\u88ab\u53d1\u73b0\u5224\u65ad\u5bfc\u81f4\u5168\u5c40\u53d8\u91cf\u7684\u5f15\u5165.<\/li>\n<li><strong>No try-catch<\/strong><br \/> \u201c\u4e0d\u8981<code>try-catch<\/code>\u201d\uff0c\u9009\u4e2d\u5219\u610f\u5473\u7740QUnit\u4f1a\u5728<code>try-catch<\/code>\u8bed\u53e5\u5916\u8fd0\u884c\u56de\u8c03\uff0c\u6b64\u65f6\uff0c\u5982\u679c\u6d4b\u8bd5\u51fa\u73b0\u5f02\u5e38\uff0c\u6d4b\u8bd5\u5c31\u4f1a\u505c\u6b62\u3002\u8fd9\u6709\u4ec0\u4e48\u7528\u5462\uff1f\u8981\u77e5\u9053\uff0c\u6709\u4e9b\u6d4f\u89c8\u5668\u7684\u8c03\u8bd5\u5de5\u5177\u662f\u76f8\u5f53\u5f31\u7684\uff0c\u5c24\u5176IE6\uff0c\u4e00\u4e2a\u672a\u5904\u7406\u7684\u5f02\u5e38\u8981\u6bd4\u6355\u83b7\u7684\u5f02\u5e38\u53ef\u4ee5\u63d0\u4f9b\u66f4\u591a\u7684\u4fe1\u606f\u3002\u5373\u4f7f\u518d\u6b21\u629b\u51fa\uff0c\u7531\u4e8eJavaScript\u4e0d\u64c5\u957f\u5f02\u5e38\u5904\u7406\uff0c\u539f\u6765\u7684\u5806\u6808\u8ddf\u8e2a\u5728\u5927\u591a\u6570\u6d4f\u89c8\u5668\u91cc\u90fd\u4e22\u5931\u4e86\u3002\n<p>\u8fd9\u663e\u7136\u662f\u4e00\u4e2a\u6709\u7740\u7279\u6b8a\u76ee\u7684\u7684\u5de5\u5177\u3002\u7136\u800c\uff0c\u4e00\u65e6\u4f60\u9047\u5230\u4e00\u4e2a\u5f02\u5e38\uff0c\u540c\u65f6\u65e0\u6cd5\u8ffd\u6eaf\u771f\u6b63\u9519\u8bef\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u5de5\u5177\u5c31\u663e\u5f97\u5f88\u6709\u7528\u4e86\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u4e5d\u3001\u66f4\u9ad8\u6548\u7684\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u5bf9\u4e8e\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1(TDD &#8211; <a href=\"http:\/\/msdn.microsoft.com\/en-us\/magazine\/gg650426.aspx\">test-driven development<\/a>)\u800c\u8a00\uff0cQUnit\u662f\u76f8\u5f53\u4e0d\u9519\u7684\u63d2\u4ef6\u3002\u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u7a0d\u4f5c\u8c03\u6574\uff0cQunit\u4f1a\u53d8\u5f97\u66f4\u52a0\u6709\u7528\uff0c\u65e0\u8bba\u662f\u7ed3\u679c\u8fd8\u662f\u901f\u5ea6\u3002<\/p>\n<p style=\"text-indent:27px;\">\u5047\u8bbe\u73b0\u5728\u6709\u4e00\u4e2a\u5de8\u5927\u7684\u6d4b\u8bd5\u5957\u4ef6\uff0c\u5168\u90e8\u6d4b\u8bd5\u5b8c\u6bd5\u9700\u898110\u79d2\u949f\uff0c\u7136\u540e\u67d0\u5904\u5931\u8d25\u4e86\uff0c\u6539\u597d\u540e\uff0c\u4f60\u91cd\u65b0\u6d4b\u8bd5\uff0c\u53c8\u662f10\u79d2\u949f\uff0c\u7ed3\u679c\u53c8\u53d1\u73b0\u4e00\u4e2a\u9519\u8bef\uff0c\u53ef\u80fd\u5c31\u662f30\u79d2\u751a\u81f31\u5206\u949f\uff0c\u6240\u8c13\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1\u96be\u514d\u6ca6\u4e3a\u9e21\u808b\u3002\u867d\u7136<code>Rurun<\/code>\u8fc7\u6ee4\u53ef\u4ee5\u6709\u9488\u5bf9\u6027\u6d4b\u8bd5\uff0c\u4f46\u662f\uff0c\u53cc\u62f3\u96be\u654c\u56db\u624b\uff0c\u9519\u8bef\u5f88\u591a\u7684\u8bdd\u6839\u672c\u5e94\u4ed8\u4e0d\u6765\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u90a3\u8be5\u600e\u4e48\u529e\u5462\uff1f<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/32.gif\" align=\"absmiddle\"><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u8fd9\u79cd\u60c5\u5f62\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9\u8c03\u8bd5\u5de5\u5177\u4e2d\u7684<strong>Hide passed tests<\/strong>\u8fd9\u4e2a\u9009\u9879\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/other.png\" align=\"absmiddle\"> \u770b\u4e0a\u9762\u7684\u4ecb\u7ecd\uff0c\u8fd9\u4e2a\u5de5\u5177\u5f88\u4e00\u822c\u554a\uff0c\u8fd9\u91cc\u4e3a\u4ec0\u4e48\u53d8\u8d85\u4eba\u4e86\u5462\uff1f<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> \u5176\u5b9e<strong>Hide passed tests<\/strong>\u53ef\u4e0d\u662f\u9690\u85cf\u663e\u793a\u90a3\u4e48\u7b80\u5355\uff0c\u5176\u4f7f\u7528\u4e86HTML5 <code>sessionStorage<\/code>\u6280\u672f\uff0c\u5728\u4e0d\u7b97\u79bb\u8c31\u7684\u6d4f\u89c8\u5668\u4e0b\uff0c\u4f1a\u8bb0\u4f4f\u4e4b\u524d\u672a\u901a\u8fc7\u7684\u6d4b\u8bd5\uff0c\u7136\u540e\u9875\u9762\u91cd\u65b0\u8f7d\u5165\u7684\u65f6\u5019\u53ea\u6d4b\u8bd5\u4e4b\u524d\u90a3\u90e8\u5206\u4e3a\u901a\u8fc7\u7684\u4ee3\u7801\u3002\u663e\u7136\uff0c\u5c31\u4e0d\u4f1a\u51fa\u73b0\u4e0a\u9762\u90a3\u79cd\u6539\u4e00\u4e0b10\u79d2\u8dd1\u4e00\u904d\uff0c\u6539\u4e00\u4e0b10\u79d2\u949f\u8dd1\u4e00\u904d\u7684\u60c5\u51b5\u3002<\/p>\n<h3>\u5341\u3001\u56de\u7b54\u5f00\u59cb\u7684\u95ee\u9898\u3001\u7ed3\u8bed<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/me.png\" align=\"absmiddle\"> QUnit\u76f8\u5173\u77e5\u8bc6\u6574\u7406\u4e0b\u6765\uff0c\u6211\u5c31\u53ef\u4ee5\u5f88\u80af\u5b9a\u5730\u56de\u7b54\u4e00\u5f00\u59cb\u629b\u51fa\u7684\u95ee\u9898\uff1a\u5355\u5143\u6d4b\u8bd5\u7684\u5fc5\u8981\u6027\uff1f\u7b54\u6848\u662f\uff1a<strong>\u6709\u5fc5\u8981<\/strong>\u3002<br \/>\u5b9e\u9645\u4e0a\uff0c\u867d\u7136\u6211\u4e4b\u524d\u6ca1\u6709\u63a5\u89e6\u8fc7\u5355\u5143\u6d4b\u8bd5\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u4f46\u662f\uff0c\u81ea\u5df1\u5728\u5b9e\u9645\u5199\u7ec4\u4ef6\u3001\u65b9\u6cd5\u7684\u65f6\u5019\u90fd\u662f\u505a\u8fc7\u5355\u5143\u6d4b\u8bd5\u7684\uff0c\u4f46\u662f\uff0c\u5c5e\u4e8e\u4e00\u79cd\u4e1a\u4f59\u7684\u505a\u6cd5\u3002\u6bd4\u8f83\u597d\u7684\u5355\u5143\u6d4b\u8bd5\u5e94\u8be5\u662f\u4ee5\u4ee3\u7801\u53bb\u9a8c\u8bc1\u4ee3\u7801\uff0c\u6d4b\u8bd5\u4ee3\u7801\u4fdd\u7559\uff0c\u4ee5\u4fbf\u540e\u7eed\u53ef\u4ee5\u7ee7\u7eed\u4f7f\u7528\uff1b\u800c\u81ea\u5df1\uff0c\u7eaf\u7cb9\u662f\u4f2a\u9020\u5404\u79cd\u53ef\u80fd\u7684\u6570\u636e\uff0c\u7136\u540e\u53bb\u8dd1\u4ee3\u7801\uff0c\u662f\u5426\u62a5\u9519\u4e4b\u7c7b\uff0c\u7136\u540e\u8dd1\u901a\u4e4b\u540e\uff0c\u4e4b\u95f4\u7684\u6d4b\u8bd5\u6570\u636e\u4ec0\u4e48\u7684\u90fd\u5220\u6389\u4e86\uff0c\u53ea\u5269\u4e0b\u771f\u6b63\u9700\u8981\u7684\u8fd0\u884c\u4ee3\u7801\u3002<\/p>\n<div>\n<div style=\"text-indent:27px;\">\u5b9e\u9645\u4e0a\u8fd9\u662f\u6709\u95ee\u9898\u7684\uff1a<\/div>\n<ol style=\"margin-top:0;\">\n<li>\u5982\u679c\u8fd9\u4e2a\u65b9\u6cd5\u540e\u671f\u5185\u90e8\u903b\u8f91\u6709\u5927\u6539\uff0c\u56de\u5934\u6d4b\u8bd5\u7684\u65f6\u5019\uff0c\u81ea\u5df1\u5c82\u4e0d\u662f\u8981\u91cd\u65b0\u518d\u9020\u4e00\u904d\u6570\u636e\uff0c\u54e6\uff0c\u6211\u5b9d\u8d35\u7684\u65f6\u95f4\u554a~~\uff1b<\/li>\n<li>\u5982\u679c\u8fd9\u4e2a\u65b9\u6cd5\u540e\u671f\u5185\u90e8\u903b\u8f91\u5c0f\u6539\uff0c\u5b9e\u9645\u6d4b\u8bd5\u7684\u65f6\u5019\uff0c\u7cbe\u529b\u6210\u672c\u7b49\u539f\u56e0\uff0c\u5f80\u5f80\u5c31\u53ea\u4f1a\u6d4b\u8bd5\u4fee\u6539\u7684\u8fd9\u90e8\u5206\u3002\u5f88\u53ef\u80fd\u5c31\u4f1a\u5bfc\u81f4\u56de\u5f52\u9519\u8bef\uff08A\u5904\u6539\u52a8\u89e6\u53d1B\u5904\u7684\u65e7bug\uff09\u3002\u5982\u679c\u4fdd\u7559\u6709\u5b8c\u6574\u7684\u5355\u5143\u6d4b\u8bd5\u4ee3\u7801\uff0c\u56e0\u4e3a\u60f3\u7701\u4e8b\u800c\u51fa\u73b0\u7684\u56de\u5f52\u9519\u8bef\u663e\u7136\u5c31\u65e0\u6240\u9041\u5f62\u4e86\uff01<\/li>\n<\/ol>\n<\/div>\n<p style=\"text-indent:27px;\">\u53ef\u89c1\uff0c\u5c31\u4e2a\u4eba\u800c\u8a00\uff0c\u5355\u5143\u6d4b\u8bd5\u7684\u601d\u60f3\u662f\u6709\u7684\uff0c\u4f46\u662f\uff0c\u5355\u5143\u6d4b\u8bd5\u7684\u505a\u6cd5\u6709\u95ee\u9898\u3002\u501f\u52a9\u7c7b\u4f3cQunit\u8fd9\u6837\u7684\u5de5\u5177\u662f\u5f88\u597d\u7684\u9009\u62e9\u3002\u56e0\u6b64\uff0c\u63a5\u4e0b\u6765\uff0c\u6211\u4f1a\u5728\u56e2\u961f\u4e2d\u63a8\u5e7f\u5355\u5143\u6d4b\u8bd5\u3002\u78e8\u5200\u4e0d\u8bef\u780d\u67f4\u5de5\uff0c\u5927\u5bb6\u6743\u8861\u6210\u672c\u6536\u76ca\u7b49\uff0c\u53ef\u4ee5\u5728\u5173\u952e\u65b9\u6cd5\uff08\u5982\u679c\u521a\u63a5\u89e6\uff0c\u6ca1\u5fc5\u8981\u6240\u6709\u7684\u65b9\u6cd5\uff09\u4e0a\u8bd5\u8bd5\u5355\u5143\u6d4b\u8bd5\uff0c\u83b7\u53d6\uff0c\u4f60\u4f1a\u559c\u6b22\u4e0a\u5b83\u7684\u3002<\/p>\n<p style=\"text-indent:27px;\">\u8d70\u904d\u4e07\u6c34\u5343\u5c71\uff0c\u7ec8\u4e8e\u2026\u2026\u770b\u5230\u4e86\u4e00\u5bb6\u6e14\u5177\u5e97\uff0c\u6545\u4e8b\u7ed3\u675f\u4e86\u3002\u7531\u4e8e\u8def\u4e0a\u8d70\u5f97\u5306\u5fd9\uff0c\u6cbf\u9014\u53ef\u80fd\u8e29\u5230\u4e86\u82b1\u82b1\u8349\u8349\uff0c\u6b22\u8fce\u6307\u6b63\uff0c\u6b22\u8fce\u4ea4\u6d41\u3002\u611f\u8c22\u60a8\u4e00\u76f4\u9605\u8bfb\u5230\u6b64\u5904\uff01<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u81ea<a href=\"http:\/\/www.zhangxinxu.com\/\">\u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<\/a>[<a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a>]<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3170\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=3170<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3170\"><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201304\/qunit.jpg\" height=\"170\" class=\"imgpad mb10\" title=\"\u70b9\u51fb\u67e5\u770b\u672c\u6587\"><\/a><br \/>\n\u5982\u679c\u60a8\u5bf9\u5355\u5143\u6d4b\u8bd5\u611f\u5174\u8da3\uff0c\u672c\u6587\u5185\u5bb9\u80af\u5b9a\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u7684\uff0c\u6587\u7ae0\u6bd4\u8f83\u957f\u2026\u2026\u5509\uff0c\u53cd\u6b63\u6211\u4e0d\u60f3\u591a\u8bf4\u4e86\uff0c\u4f60\u77e5\u9053\u7684\uff0c\u6709\u56fe\u7247\u7684\u6587\u7ae0\u90fd\u662f\u6211\u4e2a\u4eba\u89c9\u5f97\u6709\u5206\u91cf\u7684\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[14,788,787,211,719],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/3170"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3170"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/3170\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}