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

gaetan

02/09/2018, 1:31 PM
Sorry to mention you @elizarov but don’t you have an idea of how to do that?
e

elizarov

02/09/2018, 9:53 PM
What is that thenable promise that qunit needs? Why would a regular JS Promise not work?
(I’ve never tried qunit myself)
g

gaetan

02/09/2018, 10:02 PM
QUnit.test() can automatically handle the asynchronous resolution of a Promise on your behalf if you return a thenable Promise as the result of your callback function.
Qunit needs a
then
function on the promise.
g

gaetan

02/10/2018, 1:07 PM
When I run this code:
Copy code
@Test
    fun testPromise(): Promise<String> =
        promise {
            delay(1000)
            assertTrue(true)
            "OK"
        }
The result captured by qunit as
promise
is of type Unit and
promise.then
is undefined which causes the problem. When I do some plain javascript test (working):
Copy code
QUnit.test( "a Promise-returning test", function( assert ) {
    return new Promise(function (resolve, reject) {
        setTimeout(function () {
            assert.ok(true);
            resolve("result");
        }, 1500);
    });
});
promise
is a Promise object with
then
defined as a function.
Ok, I think I found the bug. It’s on FrameworkAdapter: https://github.com/JetBrains/kotlin/blob/e43a145614220fb0d2f596fb19ce28092965e794/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/FrameworkAdapter.kt#L52 The signature of
testFn
should be
()->Any
to give back the result of the test function call to Qunit, allowing it to manage an potential Promise.
e

elizarov

02/10/2018, 1:57 PM
Would you submit http://kotl.in/issue, please
g

gaetan

02/10/2018, 1:58 PM
e

elizarov

02/10/2018, 2:01 PM
Thanks a lot!
👍 1
5 Views