How do you assert matchers on nested object conten...
# kotest
l
How do you assert matchers on nested object contents? Something like capturing slots in MockK. E.g. I have an object like this:
Copy code
Success(Either.Left(IOError(cause=com.google.gson.stream.MalformedJsonException)))
I want to assert certain things: • that the contents of
Success
is of type
Left
• that the contents of
Left
is of type
IOError
• that the
cause
is of type
MalformedJsonException
s
Are you using arrow ?
l
Yes
s
And Success here is a kotlin Result ?
l
No
It's a custom class from Retrofit I guess
But my question is more general
s
ok, well for things like Arrow, we offer matchers that will smart cast as well as return the contained value
l
What about the `IOError`'s
cause
property type?
s
Copy code
val v = either.shouldBeLeft()
v shouldBe "whatever"
or
Copy code
either.shouldBeLeft().shouldBe("whatever")
👍 1
l
Can I somehow extract it?
And assert that its type is
MalformedJsonException
?
I don't want to check equality, I just want to check the type of the
cause
property
s
either.shouldBeLeft().cause.shouldBeInstanceOf<MalformedJsonException>()
l
ah ok, thanks!