Scalatest Playframework 必须包含 List[String]

Scalatest Playframework must contain List[String]

我正在使用 playframework 2.4.x,这个库

"org.scalatest" %% "scalatest" % "2.2.1" % "test"
"org.scalatestplus" %% "play" % "1.4.0-M3" % "test"

我想检查我在测试中构建的列表中是否有一些字符串,这是代码

val userTeams = validateAndGet((teamsUserResponse.json \ "teams").asOpt[List[TeamUser]]).map( x => x.teamKey )
userTeams must contain ("team1", "team2")

但是我收到这个错误

List("team1", "team2") did not contain element (team1,team2)

如果你写 ("team1", "team2") 那么你实际上是在创建一个包含两个字符串的元组,从 ScalaTest 匹配器的角度来看,它是一个元素。

Based on documentation 你必须使用 allOf:

userTeams must contain allOf ("team1", "team2")