首页 > 编程语言 > 详细

JavaScript 自定义单元测试

时间:2015-04-15 08:22:24      阅读:279      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <script>
        ‘use strict‘;
        var yyTester = (function(){
            var testFunctions = [],
                testDesc = [];

            function describe (desc, func) {
                if (testFunctions.indexOf(func) < 0){
                    testFunctions.push(func);
                    testDesc.push(desc);
                }
            }

            function undescribe (func) {
                var i = testFunctions.indexOf(func);
                if (i >= 0){
                    testFunctions.splice(i, 1);
                    testDesc.splice(i, 1);
                }
            }

            function runTest(){
                for (var i = 0, l = testFunctions.length; i < l; ++i){
                    console.log(testDesc[i]);
                    testFunctions[i]();
                }
            }

            return {
                $describe : describe , 
                $undescribe: undescribe,
                $runTest: runTest
            };
        })();
            
        (function(){
            yyTester.$describe(‘数组测试‘, function(){
                var a = [];
                var aValue = 1;
                a.push(aValue);
                console.assert(a.length == 1);
                console.assert(aValue == a[a.length - 1]);
                console.assert(a.indexOf(aValue) == a.length - 1);
                a.pop();
                console.assert(a.length == 0);
            });
            
            yyTester.$runTest();
        })();
        </script>
    </head>
    <body>
    </body>
</html>

 

JavaScript 自定义单元测试

原文:http://www.cnblogs.com/yaoyu126/p/4427539.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!