Skip to content

Commit

Permalink
fix: shouldContainJsonKey should be true for keys with null values (#…
Browse files Browse the repository at this point in the history
…3128)

Co-authored-by: Michael Sewell <michael@sewell.blog>
  • Loading branch information
msewell and Michael Sewell committed Jul 29, 2022
1 parent e1b4b48 commit b4dc446
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ fun containJsonKey(path: String) = object : Matcher<String?> {
else -> if (value.length < 50) value.trim() else value.substring(0, 50).trim() + "..."
}

val passed = try {
value != null && JsonPath.read<String>(value, path) != null
val passed = value != null && try {
JsonPath.read<String>(value, path)
true
} catch (t: PathNotFoundException) {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,10 @@ class JvmJsonAssertionsTest : StringSpec({
use(nullableJson)
}
}

"test key with null value" {
val testJson1 = """ { "nullable" : null } """
testJson1.shouldContainJsonKey("$.nullable")
testJson1.shouldContainJsonKeyValue("$.nullable", null as Any?)
}
})

0 comments on commit b4dc446

Please sign in to comment.