【问题标题】:Meteorjs test Meteor methodsMeteorjs 测试 Meteor 方法
【发布时间】:2016-08-10 08:31:31
【问题描述】:

我有以下要测试的简单 Meteor 方法。 它将给定的对象插入到我的集合中

Meteor.methods({
  insertHelper(profile){
      HelperCollection.insert(profile);
      return true;
   },
}

对于测试,我使用“dispatch:mocha-phantomjs” 到目前为止,我的测试如下:

describe('methods', () => {
  it('can delete owned task', () => {
    Meteor.call('insertHelper',{a: 1});
  });
});

运行测试时,我收到消息“错误:找不到方法 'insertHelper' [404]”

那么我怎样才能从我的测试套件中访问我的 Meteor 方法呢?

【问题讨论】:

  • 您是否在测试文件中包含方法文件?
  • 谢谢!我忘了在 require('../lib/lib/methods.js'); 中包含我的 methods.js 文件;

标签: testing meteor mocha.js


【解决方案1】:

正如 cmets 中所讨论的,我们必须包含定义 Meteor 方法的文件才能对其进行测试:

import '/path/to/method/file.js';

require

require('/path/to/methos/file.js');

编辑

Meteor advises 使用 import 而不是使用 require,如果可以的话。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 2016-04-22
    相关资源
    最近更新 更多