Reputation: 23
I have a problem with Meteor.methods. I need to test quite complicated function but i don't know how get the return value. For my own needs I wrote a trivial code:
Meteor.methods({
returnTrue: function() {
return true;
},
returnFalse: function(){
return false;
}
});
describe("Function", function() {
var tmp;
it("expect to be true", function(){
Meteor.call('returnTrue', function(error, result){
if(error){
tmp = false;
}
else{
tmp = result;
}
});
expect(tmp).toBe(true);
});
});
And in my test i have Expected undefined to be true. I was trying to go through it using Session.set and Session.get but with the same result. Any idea how can i do that?
Upvotes: 1
Views: 179
Reputation: 4820
Here is a question that might peak your interest. A few things are misguided in your code:
expect
is called outside of the method's callback, hence tmp
is not set yet!Here is a suggestion!
describe("Function", function() {
var tmp;
it("expect to be true", function(){
spyOn(Meteor, "call").and.callThrough(); // to actually call the method
Meteor.call('returnTrue', function(error, result){
if(error){
tmp = false;
}
else{
tmp = result;
}
expect(tmp).toBe(true); // moved the check inside the callback, once the call is actually executed
});
expect(Meteor.call).toHaveBeenCalled(); // check if the method has been called
});
});
Upvotes: 1