Yann
Yann

Reputation: 144

Meteor-stubs spyOn Accounts not working when testing package

I am facing a weird behavior and I hope you could help me on it.

I am testing my package using sanjo:[email protected] and velocity:[email protected]'
In my tests I do:

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

Works well for Meteor.users.

But when using spyOn on Accounts it doesn't work. If I do this in my test method:

spyOn(Accounts, 'setPassword').and.callFake(function() {
  // do nothing
});
var result = MyService.changePassword(user, newPassword);
expect(Accounts.setPassword).toHaveBeenCalled();

html-reporter reports:

Expected spy setPassword to have been called.

Any idea ?
Thanks for your help.
Yann

Upvotes: 0

Views: 125

Answers (1)

Yann
Yann

Reputation: 144

Ok I have solved the issue.

Thanks to stackoverflow Meteor: ReferenceError: Accounts is not defined

Use api.imply to give your app access to the exported symbols of your package dependencies.

I have added it in my package.js file:

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

See full exchange here: https://forums.meteor.com/t/meteor-stubs-spyon-accounts-not-working-when-testing-package/11109/9

Upvotes: 0

Related Questions