scala play 2.5 测试需要隐式 Flash 的视图
scala play 2.5 testing views that needs implicit Flash
如何测试需要隐式 flash 变量的旋转视图?
例如:
测试
"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
value/variable?
我需要注入 WithApplication
还是扩展那个 trait
?
足以:
import play.api.mvc.Flash
"render view" in new WithApplication {
contentAsString(views.html.index()(new Flash()) must contain("Hello")
}
如何测试需要隐式 flash 变量的旋转视图?
例如:
测试
"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
value/variable?
我需要注入 WithApplication
还是扩展那个 trait
?
足以:
import play.api.mvc.Flash
"render view" in new WithApplication {
contentAsString(views.html.index()(new Flash()) must contain("Hello")
}