Jasmine 2.0 SpecRunner vs Karma [英] Jasmine 2.0 SpecRunner vs Karma

查看:111
本文介绍了Jasmine 2.0 SpecRunner vs Karma的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Jasmine,我能够使用Html中的SpecRunner就好了。但是当我配置Karma时遇到了差异:

I just started using Jasmine and I was able to use the SpecRunner from the Html just fine. However when I configured Karma I encountered a discrepancy:

describe('Calculator', function(){
    var obj;
    beforeEach(function(){
        //initialize object
        obj = new Object();

        this.addMatchers({
            toBeFive: function () {
                return {
                    compare: function (actual, expected) {
                        return {
                            pass: actual === 5,
                            message: actual + ' is not exactly 5'
                        }
                    }
                };
            },

这段代码无法使用SpecRunner.html:

This piece of code does not work from the SpecRunner.html:

 this.addMatchers({

相反,我必须使用它:

 jasmine.addMatchers({

这是什么包括spe crunner:

This is what is include the specrunner:

 <!-- libs... -->
  <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"></script>
  <script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"></script>
  <script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"></script>

  <!-- source files here... -->
  <script type="text/javascript" src="../../calculator/calculator.js"></script>

  <!-- test files here... -->
  <script type="text/javascript" src="spec/calculator/calculator-test.js"></script>

我得到的错误是:

TypeError: Object #<Object> has no method 'addMatchers'

请注意,Karma没有错误但是如果我使用jasmine.addMatchers( {它确实。

Please note that Karma raise no errors but if I use jasmine.addMatchers({ it does.

推荐答案

如果你运行 npm install karma-jasmine@~0.2.1 安装karma之后,这将使用正确的茉莉花版本(因为新适配器仅在几天前发布,因此默认情况下仍未更新karma以安装正确的版本)

If you run npm install karma-jasmine@~0.2.1 after installing karma this will use the correct jasmine version (karma still hasn't updated to install the right version by default as the new adapter was only released a few days ago)

这篇关于Jasmine 2.0 SpecRunner vs Karma的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆