Question. How does one get a kproperty for a neste...
# getting-started
p
Question. How does one get a kproperty for a nested property? I'm trying to do something like the following with kotest assertions:
Copy code
data class Foo(val id: Int, val description: String)
data class Bar(val foo: Foo)
                                                                               val firstFoo = Foo(1, "Bar!")
val secondFoo = Foo(2, "Bar!")                                                                               
firstFoo.shouldBeEqualToIgnoringFields(secondFoo, Foo::id) // Assertion passes
 
val firstBar = Bar(firstFoo)
val secondBar = Bar(secondFoo)
                                                                               
firstBar.shouldBeEqualToIgnoringFields(secondBar, Bar::Foo::id) // Does not compile due to unresolved reference :(
d
There really isn't a way. You would have to ignore the
Bar::foo
, and then compare. the foos:
Copy code
firstBar.shouldBeEqualToIgnoringFields(secondBar, Bar::foo)
firstBar.foo.shouldBeEqualToIgnoringFields(secondBar.foo, Foo::id)