流量存根spyOn帐户在测试包时不起作用

时间:2015-10-12 07:41:32

标签: unit-testing testing meteor meteor-velocity

我面临一种奇怪的行为,我希望你能帮助我。

我正在使用sanjo测试我的包:jasmine@0.20.2和velocity:meteor-stubs@1.1.0'
在我的测试中,我做了:

beforeEach(function () {
    MeteorStubs.install();
});

适用于Meteor.users。

但是当在帐户上使用spyOn时,它不起作用。 如果我在我的测试方法中这样做:

spyOn(Accounts, 'setPassword').and.callFake(function() {
  // do nothing
});
var result = MyService.changePassword(user, newPassword);
expect(Accounts.setPassword).toHaveBeenCalled();
html-记者报道:

Expected spy setPassword to have been called.

任何想法?
谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

好的,我已经解决了这个问题。

感谢stackoverflow Meteor: ReferenceError: Accounts is not defined

  

使用api.imply让您的应用访问导出的符号   你的包依赖。

我已将其添加到我的package.js文件中:

api.imply([
    'accounts-password'
  ]);

在此处查看完整交换: https://forums.meteor.com/t/meteor-stubs-spyon-accounts-not-working-when-testing-package/11109/9