BlanketJS + Jasmine 2.0 不工作

BlanketJS + Jasmine 2.0 not working(BlanketJS + Jasmine 2.0 不工作)
本文介绍了BlanketJS + Jasmine 2.0 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我一直在使用 Jasmine 2.0.0 进行测试,它可以正常工作.但是当我将 BlanketJS 附加到我的代码时出现了问题.

I have been testing with Jasmine 2.0.0 and it works without any problem. But there's a problem when I append BlanketJS to my code.

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

I used a specRunner(https://github.com/alex-seville/blanket/blob/master/test/jasmine-requirejs/runner.html) that works with Jasmine 1.3.1. But It does not work when I replace Jasmine 1.3.1 with Jasmine 2.0.0,

这是来自 BlanketJS 存储库的原始代码:

Here's original code from BlanketJS repo:

<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 文件并更改了如下代码:

and I added Jasmine 2.0.0 files and changed this code like below:

....
<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 页面?请给我一个解决方案.谢谢.

How can I run this specRunner page without problems? Please give me a solution. thanks.

推荐答案

Blanket 适配器使用 currentRunner 但在 2.0 中不再存在.Blanket Jasmine 适配器需要更新,因为这和报告器界面都已更改.

the Blanket adapter uses currentRunner but that doesn't exist in 2.0 anymore. The Blanket Jasmine adapter needs to be updated as both this and the reporter interface has changed.

打开你的 jasmine-blanket.js 文件并将底部的代码替换为:

Open up your jasmine-blanket.js file and replace the code at the bottom with this:

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();
        }
    });

那么它应该会按预期进行.

Then it will should as intended.

ETA - 我个人会改用伊斯坦布尔,因为毯子现在似乎很少更新(如果有的话).伊斯坦布尔拥有更完整的覆盖率统计数据(不仅仅是线路 - 分支等),并且可以导出到 lcov 以获取 Code Climate 等工具.它可以与 Jasmine 或任何测试框架完美配合.

这篇关于BlanketJS + Jasmine 2.0 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Drag amp; Drop with Protractor by Repeater(拖动amp;通过中继器使用量角器掉落)
Getting the position of the element in a list when it#39;s drag/dropped (ui.sortable)(拖放时获取元素在列表中的位置(ui.sortable))
Detecting HTML5 Drag And Drop support in javascript(在 javascript 中检测 HTML5 拖放支持)
HTML5 drop event doesn#39;t work unless dragover is handled(除非处理了拖动,否则 HTML5 放置事件不起作用)
How to use jQuery#39;s drop event to upload files dragged from the desktop?(如何使用 jQuery 的 drop 事件上传从桌面拖动的文件?)
Drop image into contenteditable in Chrome to the cursor(将图像拖放到 Chrome 中的 contenteditable 到光标处)