javascript – BlanketJS Jasmine 2.0不工作

前端之家收集整理的这篇文章主要介绍了javascript – BlanketJS Jasmine 2.0不工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经使用Jasmine 2.0.0进行测试,它没有任何问题.
但是当我将BlanketJS附加到我的代码时有一个问题.

我使用了与Jasmine 1.3.1一起使用的specRunner(https://github.com/alex-seville/blanket/blob/master/test/jasmine-requirejs/runner.html).但是当我用茉莉花2.0.0替换茉莉花1.3.1时,它不起作用,

这是来自BlanketJS的原始代码

<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="../vendor/jasmine.css">
<script type="text/javascript" src="../vendor/jasmine.js"></script>
<script type="text/javascript" src="../vendor/jasmine-html.js"></script>
<script type="text/javascript" src="../helpers/console_runner.js"></script>
<script type="text/javascript" src="../../node_modules/requirejs/require.js"></script>
<script type="text/javascript" data-cover-only="code/" data-cover-never="['all.tests','code/tests']" 
src="../../dist/qunit/blanket.js"> </script>
<script type="text/javascript" src="../../src/adapters/jasmine-blanket.js"></script>

<script type="text/javascript">
    if (window.require && typeof (window.require.config) === 'function') {
        require.config({
            baseUrl: './code'
        });
    }
</script>
<script type="text/javascript" src="code/all.tests.jasmine.js"></script>

<script type="text/javascript">
    (function () {
        window.blanketTestJasmineExpected=2;

        var jasmineEnv = jasmine.getEnv();
        jasmineEnv.updateInterval = 1000;

        var htmlReporter = new jasmine.HtmlReporter();
        var oldResult = htmlReporter.reportRunnerResults;

        jasmineEnv.addReporter(htmlReporter);

         /* this is just for our automated tests */
          window.jasmine_phantom_reporter = new jasmine.ConsoleReporter;

          jasmineEnv.addReporter(jasmine_phantom_reporter);
          /*   */

        jasmineEnv.specFilter = function (spec) {
            return htmlReporter.specFilter(spec);
        };

        var currentWindowOnload = window.onload;
         window.onload = function() {
            if (currentWindowOnload) {
              currentWindowOnload();
            }
            execJasmine();


          };

          function execJasmine() {
            jasmineEnv.execute();
          }

    })();
</script>
</head>
<body>
</body>
</html>

添加了Jasmine 2.0.0文件,并更改了以下代码

....
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="../vendor/jasmine.css">
<script type="text/javascript" src="../vendor/jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="../vendor/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="../vendor/jasmine-2.0.0/boot.js"></script>
<script type="text/javascript" src="../helpers/console_runner.js"></script>
....

打印的错误消息:

Uncaught TypeError: Cannot read property 'env' of undefined jasmine-html.js:38
Uncaught TypeError: Object #<Env> has no method 'currentRunner' jasmine-blanket.js:76

如何运行这个specRunner页面没有问题?请给我一个解决方案谢谢.

解决方法

该毯子适配器使用currentRunner,但不再存在2.0.
毯子茉莉花适配器需要更新,因为这两个记者界面已经改变.

打开你的jasmine-blanket.js文件,并用下面的代码替换下面的代码

BlanketReporter.prototype = {
        specStarted: function(spec) {
            blanket.onTestStart();
        },specDone: function(result) {
            var passed = result.status === "passed" ? 1 : 0;
            blanket.onTestDone(1,passed);
        },jasmineDone: function() {
            blanket.onTestsDone();
        },log: function(str) {
            var console = jasmine.getGlobal().console;

            if (console && console.log) {
                console.log(str);
            }
        }
    };

    // export public
    jasmine.BlanketReporter = BlanketReporter;

    //override existing jasmine execute
    var originalJasmineExecute = jasmine.getEnv().execute;
    jasmine.getEnv().execute = function(){ console.log("waiting for blanket..."); };


    blanket.beforeStartTestRunner({
        checkRequirejs:true,callback:function(){
            jasmine.getEnv().addReporter(new jasmine.BlanketReporter());
            jasmine.getEnv().execute = originalJasmineExecute;
            jasmine.getEnv().execute();
        }
    });

那么它应该是如意的.

ETA – 个人我会改用伊斯坦布尔,因为现在毯子似乎被稀疏地更新了(如果有的话).伊斯坦布尔具有更完整的覆盖率统计数据(不仅仅是分支机构等),并且可以将其导出为lcov,用于“气候”(Code Climate)等工具.它与茉莉花或任何测试框架完美无缺地配合使用.

猜你在找的JavaScript相关文章