我现在有一个快递/节点应用我想测试,并而是回应,它给在的req.flash('warn', 'message goes here');
你如何测试req.flash()快递?
不幸的是形式,对express.js文档不描述这个消息如何传播到客户端非常彻底。
我知道expresso有一个测试响应对象的assert.response()函数。我想知道Flash的消息在哪里,以及如何以类似的方式测试它(或者如果这不可能,我应该通过响应对象发送所有消息)。
我现在有一个快递/节点应用我想测试,并而是回应,它给在的req.flash('warn', 'message goes here');
你如何测试req.flash()快递?
不幸的是形式,对express.js文档不描述这个消息如何传播到客户端非常彻底。
我知道expresso有一个测试响应对象的assert.response()函数。我想知道Flash的消息在哪里,以及如何以类似的方式测试它(或者如果这不可能,我应该通过响应对象发送所有消息)。
我不认为这应该是这样工作的。您不能仅仅使用req.flash()
作为回应请求的唯一方式。
它更像是一种简单的方法,在您的normal
模板上向用户显示消息 - 例如,插入/创建文章您可以后说:
req.flash('error', 'could not insert because .... ');
或
req.flash('info', 'article added successfully!');
我的最后一个项目我然后添加两个动态佣工到我的应用程序:
app.dynamicHelpers({
info: function (req, res) {
return req.flash('info');
},
error: function (req, res) {
return req.flash('error');
}
});
让我在我看来可以这样说......:
<% if (info !== undefined && info != "") { %>
<div class="infoBubble">
<%= info %>
</div>
<% } %>
<% if (error !== undefined && error != "") { %>
<div class="errorBubble">
<strong>Fehler</strong>: <%= error %>
</div>
<% } %>
结果是这样的:
不错,我喜欢那些帮手 - ty。 – Chance
是否查看源帮助? https://github.com/jaredhanson/connect-flash – TechplexEngineer