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

addamsson

01/18/2020, 5:55 PM
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

gcx11

01/18/2020, 6:01 PM
a

addamsson

01/18/2020, 6:05 PM
It would
will it work with the js
promise
?
also where can I import
promise
from?
g

gcx11

01/18/2020, 6:21 PM
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

addamsson

01/18/2020, 6:23 PM
thanks, will try this!
2 Views