在Karma测试中缺少功能

时间:2013-07-15 20:54:31

标签: javascript karma-runner

我正在使用Jasmine,Karma和PhantomJS自动化我的测试,但我遇到了一个问题:Phantom似乎没有正确地解析我的JS。例如,我正在使用这个模拟:

var App = function() {
  return {
    pageController : {
      currentPage : {
        on : function() {},
        toJSON : function() {},
        get : function() {
          return dark;
        }
      }
    },
    mainLayout : {
      header : {
        show : function() {},
        $el : {}
      }
    }
  };
};

console.log("in test", App());

...注销为:

PhantomJS 1.9 (Mac) LOG: [ 'in test',
  { pageController: {},
    mainLayout: { header: [Object] } } ]

app.pageController已在这里清空,导致我的测试失败。为什么会这样?&我该怎么办呢?

问题似乎与函数定义直接相关。例如:

console.log("this is a function:", function() { return 'wat'; });

产量

PhantomJS 1.9 (Mac) LOG: [ 'this is a function:', null ]

Chrome中也会出现此错误。它也会挤压茉莉花的间谍,所以我猜这与噶玛有关吗?

1 个答案:

答案 0 :(得分:1)

Karma的日志记录将所有功能报告为null。 (由于无关原因,测试失败了。)

相关问题