Is there a good quality guide on how to actually s...
# multiplatform
c
Is there a good quality guide on how to actually setup unit testing in Kotlin/JS for a multiplatform library? I've been following SO answers & stuff but the best I could find is 2 years old and very imprecise.
r
Is it not working for you out-of-the-box? JS updates since 1.3.40 changed the plugin setup significantly so a lot of stuff is there by default now. Probably just need a
browser()
or
nodejs()
call in your
js{}
target block.
For docs, multiplatform setup isn't very different from the js-specific setup in https://kotlinlang.org/docs/reference/js-project-setup.html, except you do your js stuff in
js
instead of
target
and your dependencies move to the standard mpp location instead of top-level
j
@russhwolf I am trying to do testing with coroutines in JS.
Copy code
internal actual fun <T> runTest(block: suspend () -> T): dynamic {
    return promise { block() }
}
promise isn't being resolved. Should I add a library?
r
For coroutine testing in js there's a setup descrubed in this youtrack ticket: https://youtrack.jetbrains.com/issue/KT-22228
Oh that's what you're doing
Not sure off-hand why that wouldn't work for you but make sure you have the kotlinx.coroutines dependencies added correctly
r
the js stuff is all commented-out there
and you'll need
kotlinx-coroutines-core-js
in your js sources when you uncomment it
j
Sorry. Check it again. I've pushed the latest code. It's not working even with that dependency.
r
You need core-js, not core-common
We've also drifted way off of the original thread here. Sorry Clovis
j
Copy code
val jsTest by getting {
    dependencies {
        implementation(kotlin("test-js"))

        api("io.ktor:ktor-client-mock-js:$ktorVersion")
        api("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutinesVersion")
    }
}
Its core-js
The only promise that comes up is Promise with capital P. But the one I am trying to use is small p
r
I'm not sure then. Sorry.
c
Thanks a lot @russhwolf, I didn't realize you could do that... Glad the ecosystem is becoming so simple!
j
Thanks. Got it to work!
Copy code
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise

internal actual fun <T> runTest(block: suspend () -> T): dynamic {
    return GlobalScope.promise { block() }
}