scala play 2.5测试需要隐式Flash的视图

时间:2017-06-11 17:44:07

标签: scala testing playframework specs2

如何测试需要隐式闪变量的旋转视图?

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

1 个答案:

答案 0 :(得分:0)

足以:

import play.api.mvc.Flash

"render view" in new WithApplication {
      contentAsString(views.html.index()(new Flash()) must contain("Hello")
    }