Meteorjs测试Meteor方法



我想测试下面这个简单的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方法呢?

正如在注释中所讨论的,我们必须包含定义Meteor方法的文件,以便对它们进行测试:

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

或与require:

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

编辑

流星建议使用import而不是使用require,如果可以的话。

最新更新