Is there a form of `Map<K, V>.shouldContainA...
# kotest
r
Is there a form of
Map<K, V>.shouldContainAll(expected: Map<K, V>)
which recurses into any maps in the top level structure?
I'd like this to pass:
Copy code
mapOf(
      "1" to "1",
      "2" to mapOf(
        "2.1" to "2.1",
        "2.2" to "2.2",
      )
    ) shouldLooselyMatch mapOf(
      "1" to "1",
      "2" to mapOf(
        "2.2" to "2.2",
      )
    )
And it needs to work if the map is nested inside a List too:
Copy code
mapOf(
      "1" to "1",
      "2" to listOf(
        mapOf(
        "2.1" to "2.1",
        "2.2" to "2.2",
        )
      )
    ) shouldLooselyMatch mapOf(
      "1" to "1",
      "2" to listOf(
        mapOf(
          "2.1" to "2.1",
        )
      )
    )
(As you can probably guess this is at root a json matching issue - I suspect
shouldEqualSpecifiedJson
would do it but I've got a List/Map based representation rather than a String one...)
s
there's some new json stuff in 5.3.0
e
r
No, it's not a schema check, it's a match that ignores properties not present in the expectation.
e
Okay, I don't know if there's such an assertion, I've never come across it at least. I would probably look into testing at another layer where the structure is serialized, or serialize it as part of the test. But I don't know the context here 🙂
r
It's basically
shouldEqualSpecifiedJson
, but with Maps on either side rather than strings. I could serialise the Maps to json I suppose... Or alternatively convert them to
io.kotest.assertions.json.JsonTree
and use
equalJson
with
compareJsonOptions { fieldComparison = FieldComparison.Lenient }
, which would save using a string as the intermediate step.
s
We have a should match json ignoring fields I thought ?
r
Yes, as I say the existing
shouldEqualSpecifiedJson
matcher is exactly the concept I want; I just haven't got json strings, I've got Maps.
s
Ahh now I get you
@Emil Kantis just needs to work harder 😉
😅 1
😁 1