Does KoTest has support for virtual time in tests ...
# kotest
t
Does KoTest has support for virtual time in tests ? I'm testing a component that uses
delay
and I'd like to check that at least X seconds has elapsed between 2 operations.
TestCoroutineDispatcher
from
kotlinx-coroutines-test
has this capability but I can't find a way to use it with
StringSpec
.
s
You can use the test dispatcher with kotest. Either per test or per spec.
t
Could you please elaborate ? What function/config should be used ?
s
Yep, each test in kotest is just a coroutine itself, so you can switch dispatcher with
withContext
Copy code
test("my test"){ 
  withContext(TestCoroutineDispatcher) { 
    ...
  }
}
And you could do that in a beforeSpec or beforeTest listener if you wanted to be more universal