https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

pardom

02/26/2019, 4:37 PM
Anyone have tips on testing coroutines in multiplatform projects?
runBlocking
isn’t in common so that can’t be used.
t

thana

02/26/2019, 4:54 PM
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

gildor

02/27/2019, 3:30 AM
There are a few workarounds how to test suspend code in JS (and also let to test it in MPP)
3 Views