如何在express中测试req.flash()?
我目前有一个要测试的 Express/Node 应用程序,但它给出的响应格式为 req.flash('warn', 'message gets here');
不幸的是,文档express.js 上的内容并没有非常彻底地描述此消息如何传输到客户端。
我知道 expresso 有一个 assert.response() 函数来测试响应对象。我想知道闪存消息去哪里,以及如何以类似的方式测试它(或者如果不可能,我应该通过响应对象发送所有内容)。
I currently have an express/node application I want to test, and but responses that it gives are in the form of req.flash('warn', 'message goes here');
Unfortunately, the documentation on express.js does not describe how this message travels to the client very thoroughly.
I know expresso has an assert.response() function that tests response objects. I was wondering where the flash message goes, and how I can test it in a similar way (or if it's not possible, and I should be sending everything through the response object).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为这应该是这样的。您不能仅使用
req.flash()
作为响应请求的唯一方式。它更像是一种在
普通
模板上向用户闪现消息的简单方法 - 例如,在插入/创建文章后,您可以说:或者
对于我的上一个项目,我向我的应用程序添加了两个动态助手:
这样我就可以在我看来这样说:
结果如下所示:
i don't think this is supposed to work like that. you can't just use
req.flash()
as your only way to respond to a request.it's more like an easy way to flash messages to the user on your
normal
templates - e.g. after inserting/creating an article you can either say:or
for my last project i then added two dynamic helpers to my app:
so that i can just say sth like this in my view:
result looks like this: