Skip to content

Commit ec302fd

Browse files
committed
Added test for JsUndefined.asOpt function
1 parent 9165181 commit ec302fd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>
3+
*/
4+
5+
package play.api.libs.json
6+
7+
import play.api.libs.json.Json._
8+
9+
import org.scalatest.matchers.must.Matchers
10+
import org.scalatest.wordspec.AnyWordSpec
11+
12+
class JsLookupSpec extends AnyWordSpec with Matchers {
13+
"JsLookupResult" should {
14+
val obj = Json.obj(
15+
"field" -> 123
16+
)
17+
val result = obj \ "missingField"
18+
19+
"return JsUndefined when a key is missing" in {
20+
result mustBe a[JsUndefined]
21+
}
22+
23+
"return None when calling asOpt on JsUndefined" in {
24+
result.asOpt[Int] mustEqual None
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)