如何在 Grails Webflow 中测试 flash.message?
我在 Grails 中使用 webflows,目前正在为其编写测试。现在,里面有一些东西会引发错误,因此我在重定向之前向 flash 范围设置了一条消息:
...
if (some_condition) {
flash.message = "my error message"
return error()
}
...
现在,我知道当我要在 GSP 页面中显示此消息时,我会访问 flash 消息,而
<g:if test="${message}">...
不是通常
<g:if test="${flash.message}">...
所以无论如何,我正在编写测试,我想知道如何测试消息的内容?通常,在控制器的正常操作中,我遵循 此处 中编写的内容。但是,由于这是一个网络流,即使我检查controller.flash.message/controller.params.message/controller.message,我似乎也找不到该消息。我也尝试过查看流程范围...
关于如何查看消息有什么想法吗?非常感谢!
I'm using webflows in Grails and I'm currently writing tests for it. Now, inside I've got something that throws an error so I set a message to the flash scope before redirecting:
...
if (some_condition) {
flash.message = "my error message"
return error()
}
...
Now, I know that when I'm going to display this in the GSP page, I access the flash message as
<g:if test="${message}">...
instead of the usual
<g:if test="${flash.message}">...
So anyway, I'm writing my test and I'm wondering how to test the content of the message? Usually, in normal actions in the controllers, I follow what's written in here . However, since this is a webflow, I can't seem to find the message even if I check controller.flash.message / controller.params.message / controller.message . I've also tried looking at the flow scope...
Any ideas on how to see the message then? Thanks a bunch!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的示例,您可以在 Webflow 测试中将
flash.message
作为controller.request.message
访问。我在谷歌上搜索了很多同样的问题,并且很多 webflow 文档都讨论了将所有范围合并到“视图模型”中。但我也在某处读到它将闪存范围合并到请求范围中以进行重定向。这就是促使我尝试在测试用例中查找controller.request
的原因。Based on your example, you can access your
flash.message
ascontroller.request.message
in your webflow test. I did a lot of googling for this same exact issue and a lot of webflow documentations talk about it merging all scopes into the "view model". But I also read somewhere that it merges the flash scope into the request scope for redirection. That's what prompted me to try looking in thecontroller.request
in my test case.