【发布时间】:2015-04-30 12:01:20
【问题描述】:
堆栈
使用 Mocha + Velocity (0.5.3) 进行 Meteor 客户端集成测试。假设我安装了 autopublish 包。
问题
如果 MongoDB 上的文档是从服务器插入的,客户端 mocha 测试将不会等待订阅同步,从而导致断言失败。
代码示例
服务器端Accounts.onCreateUser钩子:
Accounts.onCreateUser(function (options, user) {
Profiles.insert({
'userId': user._id,
'profileName': options.username
});
return user;
});
客户端摩卡测试:
beforeEach(function (done) {
Accounts.createUser({
'username' : 'cucumber',
'email' : 'cucumber@cucumber.com',
'password' : 'cucumber' //encrypted automatically
});
Meteor.loginWithPassword('cucumber@cucumber.com', 'cucumber');
Meteor.flush();
done();
});
describe("Profile", function () {
it("is created already when user sign up", function(){
chai.assert.equal(Profiles.find({}).count(), 1);
});
});
问题
如何让 Mocha 等待我的个人资料文档到达客户端,避免 Mocha 超时(从服务器创建)?
【问题讨论】:
标签: javascript testing meteor mocha.js velocity