Meteor-stubs spyOn Accounts not working when testing package

Hi there,

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

I am testing my package using sanjo:jasmine@0.20.2 and velocity:meteor-stubs@1.1.0’
In my tests I do:

beforeEach(function () {

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);

html-reporter reports:

Expected spy setPassword to have been called.

Any idea ?
Thanks for your help.


I have reported my issue on stack overflow


What’s inside MyService.changePassword?

A simple call:

Accounts.setPassword(user._id, password);

Let’s try to take a look inside. Can you try to console.log(Accounts.setPassword) before the call to MyService.changePassword and then again before the call to Accounts.setPassword inside the service?

console.log(Accounts.setPassword) result before service call:

{ [Function]
   future: [Function],
   async: [Function],
   asyncApply: [Function],
    { identity: [Function],
      exec: [Function],
      callThrough: [Function],
      returnValue: [Function],
      returnValues: [Function],
      throwError: [Function],
      callFake: [Function],
      stub: [Function] },
    { track: [Function],
      any: [Function],
      count: [Function],
      argsFor: [Function],
      all: [Function],
      allArgs: [Function],
      first: [Function],
      mostRecent: [Function],
      reset: [Function] } }

console.log(Accounts.setPassword) result before Accounts.setPassword(…) call:


Empty, like if the spyOn() was never called !?


The stubs package creates an empty function as can be seen here.

Are you explicitly calling the MeteorStubs.install somewhere? Perhaps you don’t even need the stubs at all since you’re manually controlling the dependencies with spies

I’m calling MeteorStubs.install() from the beforeEach() statement and MeteorStubs.uninstall() from the afterEach() statement like so:

describe('Testing', function () {
	beforeEach(function () {

	afterEach(function () {

       // Testing parts below

I will try without to see the result.

The result is : Accounts is not defined

Ok, solved the issue :smile:

Thanks to stackoverflow

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:


And everything works ok now :smile:

1 Like