【问题标题】:Unit tests in meteor can't find the code they need to test流星中的单元测试找不到他们需要测试的代码
【发布时间】:2016-03-30 04:57:45
【问题描述】:

我正在为 Meteor 中的单元测试而苦苦挣扎。我想使用速度,茉莉包,但我一定做错了什么。测试似乎没有工作,因为测试找不到要测试的代码。测试项目在 github 上可用。

我要测试的代码在这里: https://github.com/robvanpamel/coderepository/blob/master/meteor/sandwich-app/server/Services/SandwichService.js

单元测试在这里: https://github.com/robvanpamel/coderepository/blob/master/meteor/sandwich-app/tests/jasmine/server/integration/spec/SandwichServiceSpec.js 当我在单元测试中取消注释创建的 SandwichService 时,测试正常,这是正常的。

我没有在流星的其他地方进行任何配置,我认为这就是问题所在。您是否必须在指定源代码的位置放置一个 package.js 文件? Jasmine 怎么知道它在哪里可以找到我要测试的 SandwichService?这也是我得到的错误。 "ReferenceError: SandwichesService 未定义"

编辑

我能够解决它并更新了 GitHub 中的代码存储库。关键是不要使用 Javascript 原型。所以下面的行不通

function SandwichesService(){};

SandwichesService.prototype.listSandwiches = function() {
  // do stuff here
}

虽然下面的代码确实有效

SandwichService = {
  listSandwiches: function(){
      // do stuff here
  }
};

我真的不明白为什么?有人可以告诉我吗?

诚挚的问候和感谢! 抢

【问题讨论】:

    标签: meteor jasmine meteor-velocity meteor-jasmine


    【解决方案1】:

    这是 Meteor 问题,不是测试问题 :)

    您需要将 SandwichesService 放在全局命名空间中。您的第二个块默认情况下会这样做。

    试试:

    SandwichService = new SandwichesService()

    (不要使用 var)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 2021-11-16
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多