Hey guys, any idea how to test coroutines in Kotli...
# javascript
c
Hey guys, any idea how to test coroutines in KotlinJs? Most solutions I've come across workarounds that should potentially work with Kotlin Multiplatform, but not Kotlin/JS on it's own. Tried using the workaround suggested here: https://youtrack.jetbrains.com/issue/KT-22228. However, the
promise
keyword doesn't exist in Kotlin/JS alone.
c
Thanks! Will test out shortly and revert
Unfortunately, I wasn't able to get it to work in my test cases. However, I came up with a workaround using the
GlobalScope.promise
extension function:
Copy code
@BeforeTest
fun setup() {
    testPromise = Promise { resolve, _ ->
        resolve("Test done!")
    }
}

@Test
fun test_name() = GlobalScope.promise {
  //Test body

  sut.performActionWithCoroutine()
  testPromise.await() <-- Get the result of the coroutine here

  //Assertions
}