如何测试需要隐式闪变量的旋转视图?
e.g:
测试
"render view" in new WithApplication {
contentAsString(views.html.index()) must contain("Hello")
}
旋转视图:
@()(implicit flash: Flash)
<div>
@if(flash.get("error").isDefined) {
flash.get("error").getOrElse(""))
}
</div>
<p> Hello! </p>
在上面的测试中,我如何传递implicit flash:Flash
值/变量?
我是否需要注入WithApplication
或扩展trait
?
答案 0 :(得分:0)
足以:
import play.api.mvc.Flash
"render view" in new WithApplication {
contentAsString(views.html.index()(new Flash()) must contain("Hello")
}