dave08
08/18/2024, 10:07 AMval trackUsages by prepared { mutableList<String>() }
val subject by createSubject(...) {
// How can I save per test what urls were passed here? I can't just use trackUsages() since I don't have a TestDsl...
...
}
private fun createSubject(
dep1: Prepared<Foo>,
dep2: Prepared<Bar>,
fetcher: suspend Foo.(url: String) -> Baz
) = prepared { ... }
is there any clean way to do this?CLOVIS
08/18/2024, 10:09 AMdave08
08/18/2024, 10:10 AMCLOVIS
08/18/2024, 10:11 AMCLOVIS
08/18/2024, 10:17 AMval trackUsages by prepared { mutableList<String>() }
fun <A, T> TestDsl.track(block: suspend TestDsl.(A) -> T): suspend (A) -> T {
val usages = trackUsages()
return {
trackUsages += "Called with $it"
block(it)
}
}
// Usage:
test("…") {
val tracked = track { it * 2 }
tracked(1)
tracked(2)
trackUsages() shouldBe listOf("Called with 1", "Called with 2")
}
dave08
08/18/2024, 10:24 AMdave08
08/18/2024, 10:29 AMsuspend Foo.(url: String) -> Baz
, so I can't really past the TestDsl there... I'll maybe just have to pass both as parameters...