Am I misunderstanding how clues supposed to work? ...
# kotest
k
Am I misunderstanding how clues supposed to work? Tried
asClue
and
withClue
but I'm not seeing the clue included in a stacktrace 🧵
have a testing API like this:
Copy code
suspend fun <ScreenT : Screen> ScreenPresenter<ScreenT>.test(
  screen: ScreenT,
  testTimeout: Duration = 10.seconds,
  modelTimeout: Duration = 3.seconds,
  validate: suspend ReceiveTurbine<ScreenModel>.(NavigatorMock) -> Unit,
) {
  val navigator = NavigatorMock()
  withTimeoutThrowing(testTimeout) {
    val dispatcher = singleThreadedDispatcher()
    val models = moleculeFlow(Immediate) { model(navigator, screen) }
      .flowOn(dispatcher)
      .onCompletion { dispatcher.cancel() }
      .distinctUntilChanged()

    models.test(modelTimeout) {
      validate(navigator)
    }
  }
  withClue("Unconsumed Navigator events") {
    navigator.goToCalls.expectNoEvents()
    navigator.exitCalls.expectNoEvents()
  }
}
But stacktrace doesn't include the clue when
navigator.goToCalls.expectNoEvents()
assert fails
Untitled
e
What does the
expectNoEvents
definition look like?
e
Looks like we currently don't intercept non-kotest
AssertionError
s.. I think it can be fixed though. For now I think you could wrap it with
shouldNotThrowAny { }
, i.e
Copy code
withClue("Unconsumed Navigator events") {
    shouldNotThrowAny {
      navigator.goToCalls.expectNoEvents()
      navigator.exitCalls.expectNoEvents()
    }
  }
I think it can be fixed though
Looked into it a bit, and it seems a bit complicated.. 😕
a
shouldNotThrowAny
should do it in 6.0, but not in 5.9.1
k
Could
shouldNotThrowAny
be an implementation detail of
assertSoftly
?
a
you lost me
k
From library API perspective, any reason why
assertSoftly
couldn't just call
shouldNotThrowAny
internally to achieve the effect of making sure all errors are wrapped softly?
a
yeah, this is how JUnit's equivalent of
assertSoftly
work, because it takes a collection of lambdas and executes them one at a time. OTOH
assertSoftly
takes only one parameter. so whatever is inside that lambda should not be throwing exceptions.