I'm trying to write test for a twilio application. My strategy is to make a http request to my server, like what twilio will do when receiving a phone call on one of my numbers, then analyze the xml retrieved from the server response.
I tried to stub Meteor.users.find. But, I didn't succeed. The call to Meteor.users.find is from a route action. I thought maybe there is a problem with spyOn and functions inside routes actions.
So, to investigate more in the problem. I decided to make the problem simpler. Here is the code: in /server/routes.js
ExpertTest = {
foo: function () {
console.log("called");
return 4;
}
};
allo = function () {
var res = ExpertTest.foo();
console.log(res);
};
Router.route('/call-api/intro', {
where: "server",
name: "Intro",
action: function () {
ExpertTest.foo();
this.response.writeHead(200, {'Content-Type': 'application/xml; charset=utf-8'});
this.response.end();
}
});
and in tests/jasmine/server/integration/IVRSpec.js
describe("With our IVR", function () {
it("green test", function () {
spyOn(ExpertTest, "foo").and.returnValue(50);
allo();
expect(ExpertTest.foo).toHaveBeenCalled();
});
it('red test', function() {
spyOn(ExpertTest, "foo").and.returnValue(50);
var callFirstResult = HTTP.get(baseUrl + '/call-api/intro');
expect(ExpertTest.foo).toHaveBeenCalled();
});
});
and here is the error in console:
jasmine-server-integration: 1 tests failed
With our IVR red test
Expected spy foo to have been called.
http://meteor💻app/tests/jasmine/server/integration/IVRSpec.js:81:32: Expected spy foo to have been called.
Did I do something wrong?
Can anyone help me?
Thank you very much
Aucun commentaire:
Enregistrer un commentaire