Anyone have tips on testing coroutines in multipla...
# coroutines
p
Anyone have tips on testing coroutines in multiplatform projects?
runBlocking
isn’t in common so that can’t be used.
t
i had the same problem with testing JS. the solution was to declare a method in
commonTest
like that:
expect fun runTest(block: suspend () -> Unit)
that would be used to wrap the unit test testing the coroutine
on the jvm its implemented as
actual fun runTest(block: suspend () -> Unit) = runBlocking { block() }
and on js like that
Copy code
actual fun runTest(block: suspend () -> Unit): dynamic = GlobalScope.promise {
    block()
}
in the end frameworks like jasmin and mocha can await the promise and in the testcode you can e.g. call
delay
g
There are a few workarounds how to test suspend code in JS (and also let to test it in MPP)