yannd
October 9, 2015, 4:57pm
1
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 () {
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
yannd
October 12, 2015, 7:50am
2
sam
October 12, 2015, 9:03am
3
What’s inside MyService.changePassword
?
yannd
October 12, 2015, 9:07am
4
A simple call:
Accounts.setPassword(user._id, password);
sam
October 12, 2015, 10:33am
5
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?
yannd
October 12, 2015, 2:12pm
6
console.log(Accounts.setPassword) result before service call:
{ [Function]
future: [Function],
async: [Function],
asyncApply: [Function],
and:
{ identity: [Function],
exec: [Function],
callThrough: [Function],
returnValue: [Function],
returnValues: [Function],
throwError: [Function],
callFake: [Function],
stub: [Function] },
calls:
{ 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:
[Function]
Empty, like if the spyOn() was never called !?
sam
October 12, 2015, 2:56pm
7
Hmm
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
yannd
October 12, 2015, 2:59pm
8
I’m calling MeteorStubs.install() from the beforeEach() statement and MeteorStubs.uninstall() from the afterEach() statement like so:
describe('Testing', function () {
beforeEach(function () {
MeteorStubs.install();
});
afterEach(function () {
MeteorStubs.uninstall();
});
// Testing parts below
}
I will try without to see the result.
yannd
October 12, 2015, 3:10pm
9
yannd:
I’m calling MeteorStubs.install() from the beforeEach() statement and MeteorStubs.uninstall() from the afterEach() statement like so:
describe('Testing', function () {
beforeEach(function () {
MeteorStubs.install();
});
afterEach(function () {
MeteorStubs.uninstall();
});
// Testing parts below
}
I will try without to see the result.
The result is : Accounts is not defined
yannd
October 12, 2015, 3:21pm
10
Ok, solved the issue
Thanks to stackoverflow http://stackoverflow.com/questions/32058367/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'
]);
And everything works ok now
1 Like