0

我正在使用 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 中。它还创造了茉莉花间谍,所以我猜这与业力有关?

4

1 回答 1

1

Karma 的日志记录将所有功能报告为null. (测试因不相关的原因而失败)。

于 2013-07-15T21:19:42.847 回答