【发布时间】:2014-09-10 04:07:32
【问题描述】:
我想知道为什么这个 jasmine-unit 测试会卡在“加载”中。
这是我的测试,addUser 在服务器端调用 Accounts.createUser() 方法,完成后通常返回添加用户的 id:
(function () {
"use strict";
var InsertUser = function()
{
var id;
id = Meteor.methodMap.addUser('asd@asd.asd', 'asdasd', 'John', 'Doe', 'not yet', '070-111 22 33', 'ididididid', 'admin', 'info admin john', 0);
console.log("1. call method: " + id);
this.getIdOfUser = function()
{
return id;
};
};
describe("User functions", function ()
{
var userInsert;
beforeEach(function(done)
{
setTimeout(function() {
userInsert = new InsertUser();
console.log("2. before each");
done();
}, 1000);
});
it("Add user return value", function(done)
{
spyOn(userInsert, 'getIdOfUser');
console.log("3. use spy");
expect(userInsert.getIdOfUser).toHaveBeenCalled();
done();
});
});
})();
我这里尝试使用异步调用addUser的方式获取服务端方法返回的id。
如果我从浏览器控制台手动调用“addUser”方法,则添加用户有效。
【问题讨论】:
标签: unit-testing meteor jasmine velocity