I'm trying to test some code which uses coroutines...
# coroutines
a
I'm trying to test some code which uses coroutines in my common project. How can I do so if I want to
.join()
a
Job
? What I have right now looks like this:
Copy code
@Test
fun someTest {
    myObj.doSomething().join()
}
My problem is that I can't call
join()
if I want to wait for the coroutine to complete because I have no
CoroutineScope
but there is no
runBlocking
in a common project which what I usually use in my jvm tests. What can I do instead to solve this problem?
g
a
It would
will it work with the js
promise
?
also where can I import
promise
from?
g
It looks outdated, you need to add
Copy code
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutines_version"
as dependency into jsTest block. And JS declaration for newer version looks like this
Copy code
actual fun runTest(block: suspend () -> Unit): dynamic = GlobalScope.promise { block() }
a
thanks, will try this!