Mocha测试不在等待发布/订阅

编程入门 行业动态 更新时间:2024-10-25 14:24:10
本文介绍了Mocha测试不在等待发布/订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用 Mocha + Velocity(0.5.3)进行Meteor客户端集成测试.假设我已经安装了 autopublish 软件包.

Using Mocha + Velocity (0.5.3) for Meteor client-side integration tests. Let's assume that I have autopublish package installed.

如果从服务器插入了MongoDB上的文档,则客户端Mocha测试将不会等待订阅同步,从而导致断言失败.

If a document on the MongoDB was inserted from the server, the client-side mocha tests will not wait for the subscription to synchronise, causing the assertion to fail.

服务器端Accounts.onCreateUser挂钩:

Accounts.onCreateUser(function (options, user) { Profiles.insert({ 'userId': user._id, 'profileName': options.username }); return user; });

客户端Mocha测试:

Client-side Mocha Test:

beforeEach(function (done) { Accounts.createUser({ 'username' : 'cucumber', 'email' : 'cucumber@cucumber', 'password' : 'cucumber' //encrypted automatically }); Meteor.loginWithPassword('cucumber@cucumber', '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超时(从服务器创建)?

Question

How could I make Mocha wait for my profile document to make its way to the client avoiding the Mocha timeout (created from the server)?

推荐答案

您可以被动地等待文档. Mocha超时,因此如果未创建文档,它将在一段时间后自动停止.

You can reactively wait for the documents. Mocha has a timeout, so it would stop automatically after some time if the documents are not created.

it("is created already when user signs up", function(done){ Tracker.autorun(function (computation) { var doc = Profiles.findOne({userId: Meteor.userId()}); if (doc) { computation.stop(); chai.assert.propertyVal(doc, 'profileName', 'cucumber'); done(); } }); });

更多推荐

Mocha测试不在等待发布/订阅

本文发布于:2023-11-23 14:47:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   Mocha

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!