I'm trying to test a function with a `delay()`. By...
# kotest
m
I'm trying to test a function with a
delay()
. By using
coroutineTestScope = true
, Kotest is correctly skipping the delay and I can test the output. However, I also want to test that it delays for the correct amount of time. How can I check how much virtual time has elapsed? I thought
testCoroutineScheduler.currentTime
would tell me, but it returns
0
.
oh, it's marked as internal 🤔
s
A more hands-off approach would just be to use
delay()
in your test itself. E.g.
Copy code
delay(expectedDuration - 1)
assert(thing.isNotDone)
delay(1)
assert(thing.isDone)
m
I don't want my test to actually take a long time to run, because of the delay
s
It won't—delays in the test are skipped by the scheduler, just the same as delays in the code under test
m
Hmm, that could work then. I would presumably have to launch a separate coroutine to run my function, so I can concurrently do these delayed assertions?
s
That could work, yes. Maybe an
async
coroutine, and then you can use its
Deferred
result to check whether it's finished.