https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
d

dan.the.man

09/12/2020, 6:05 PM
I'm trying to set up some tests with suspend functions, It works fine on JVM but I'm curious what people are doing for JS and native?
l

louiscad

09/12/2020, 6:34 PM
runBlocking exists in native. For JS, you can wrap the suspend function into a promise.
c

Casey Brooks

09/12/2020, 6:39 PM
#kotest works on JVM and JS and everything is suspending by default (but I don’t think Native is supported yet)
👍 1
d

dan.the.man

09/12/2020, 7:22 PM
I have
Copy code
actual fun runTest(block: suspend (scope : CoroutineScope) -> Unit):
        dynamic = GlobalScope.promise { block(this) }
for my JS implementation but the test still just completes instead of failing like i'd expect. On JVM this is just runBlocking{} and it all performs how you would expect. What am I doing wrong?
l

louiscad

09/12/2020, 7:23 PM
@dan.the.man I don't think you should have it with the
actual
modifier.
d

dan.the.man

09/12/2020, 7:24 PM
In my common module I have
Copy code
expect fun runTest(block: suspend (scope : CoroutineScope) -> Unit)
To try and test common code on each platform
l

louiscad

09/12/2020, 7:26 PM
Yes I understand, but `expect`/`actual` is for identical signatures. It's not the case here as the JS one returns a promise in form of
dynamic
(Not sure why you return
dynamic
BTW)
Here's the issue you want to follow and look for regarding workarounds @dan.the.man: https://youtrack.jetbrains.com/issue/KT-22228
d

dan.the.man

09/12/2020, 7:28 PM
I'm not entirely sure either, I've only done jvm kotlin before
9 Views